File tree 3 files changed +10
-6
lines changed
3 files changed +10
-6
lines changed Original file line number Diff line number Diff line change 10
10
"Topic :: Software Development :: Libraries :: Python Modules"
11
11
],
12
12
description = "CS50 library for Python" ,
13
- install_requires = ["SQLAlchemy" ],
13
+ install_requires = ["SQLAlchemy" , "sqlparse" ],
14
14
keywords = "cs50" ,
15
15
name = "cs50" ,
16
16
package_dir = {"" : "src" },
17
17
packages = ["cs50" ],
18
18
url = "https://github.com/cs50/python-cs50" ,
19
- version = "2.0 .0"
19
+ version = "2.1 .0"
20
20
)
Original file line number Diff line number Diff line change 3
3
import logging
4
4
import re
5
5
import sqlalchemy
6
+ import sqlparse
6
7
import sys
7
8
import warnings
8
9
@@ -86,6 +87,10 @@ def process(value):
86
87
else :
87
88
return process (value )
88
89
90
+ # allow only one statement at a time
91
+ if len (sqlparse .split (text )) > 1 :
92
+ raise RuntimeError ("too many statements at once" )
93
+
89
94
# raise exceptions for warnings
90
95
warnings .filterwarnings ("error" )
91
96
Original file line number Diff line number Diff line change 6
6
from cs50 .sql import SQL
7
7
8
8
class 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')" )
11
12
12
13
def test_delete_returns_affected_rows (self ):
13
14
rows = [
@@ -24,8 +25,6 @@ def test_delete_returns_affected_rows(self):
24
25
def test_insert_returns_last_row_id (self ):
25
26
self .assertEqual (self .db .execute ("INSERT INTO cs50(val) VALUES('foo')" ), 1 )
26
27
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 )
29
28
30
29
def test_select_all (self ):
31
30
self .assertEqual (self .db .execute ("SELECT * FROM cs50" ), [])
You can’t perform that action at this time.
0 commit comments