File tree Expand file tree Collapse file tree 3 files changed +10
-6
lines changed
Expand file tree Collapse file tree 3 files changed +10
-6
lines changed Original file line number Diff line number Diff line change 1010 "Topic :: Software Development :: Libraries :: Python Modules"
1111 ],
1212 description = "CS50 library for Python" ,
13- install_requires = ["SQLAlchemy" ],
13+ install_requires = ["SQLAlchemy" , "sqlparse" ],
1414 keywords = "cs50" ,
1515 name = "cs50" ,
1616 package_dir = {"" : "src" },
1717 packages = ["cs50" ],
1818 url = "https://github.com/cs50/python-cs50" ,
19- version = "2.0 .0"
19+ version = "2.1 .0"
2020)
Original file line number Diff line number Diff line change 33import logging
44import re
55import sqlalchemy
6+ import sqlparse
67import sys
78import warnings
89
@@ -86,6 +87,10 @@ def process(value):
8687 else :
8788 return process (value )
8889
90+ # allow only one statement at a time
91+ if len (sqlparse .split (text )) > 1 :
92+ raise RuntimeError ("too many statements at once" )
93+
8994 # raise exceptions for warnings
9095 warnings .filterwarnings ("error" )
9196
Original file line number Diff line number Diff line change 66from cs50 .sql import SQL
77
88class SQLTests (unittest .TestCase ):
9- def multi_inserts_enabled (self ):
10- return True
9+
10+ def test_multiple_statements (self ):
11+ self .assertRaises (RuntimeError , self .db .execute , "INSERT INTO cs50(val) VALUES('baz'); INSERT INTO cs50(val) VALUES('qux')" )
1112
1213 def test_delete_returns_affected_rows (self ):
1314 rows = [
@@ -24,8 +25,6 @@ def test_delete_returns_affected_rows(self):
2425 def test_insert_returns_last_row_id (self ):
2526 self .assertEqual (self .db .execute ("INSERT INTO cs50(val) VALUES('foo')" ), 1 )
2627 self .assertEqual (self .db .execute ("INSERT INTO cs50(val) VALUES('bar')" ), 2 )
27- if self .multi_inserts_enabled ():
28- self .assertEqual (self .db .execute ("INSERT INTO cs50(val) VALUES('baz'); INSERT INTO cs50(val) VALUES('qux')" ), 4 )
2928
3029 def test_select_all (self ):
3130 self .assertEqual (self .db .execute ("SELECT * FROM cs50" ), [])
You can’t perform that action at this time.
0 commit comments