Skip to content

v6.0.4 #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -16,5 +16,5 @@
package_dir={"": "src"},
packages=["cs50"],
url="https://github.com/cs50/python-cs50",
version="6.0.3"
version="6.0.4"
)
7 changes: 4 additions & 3 deletions src/cs50/sql.py
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ def execute(self, sql, *args, **kwargs):
import warnings

# Parse statement, stripping comments and then leading/trailing whitespace
statements = sqlparse.parse(sqlparse.format(sql, keyword_case="upper", strip_comments=True).strip())
statements = sqlparse.parse(sqlparse.format(sql, strip_comments=True).strip())

# Allow only one statement at a time, since SQLite doesn't support multiple
# https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.execute
@@ -130,8 +130,9 @@ def execute(self, sql, *args, **kwargs):
# Infer command from (unflattened) statement
for token in statements[0]:
if token.ttype in [sqlparse.tokens.Keyword, sqlparse.tokens.Keyword.DDL, sqlparse.tokens.Keyword.DML]:
if token.value in ["BEGIN", "DELETE", "INSERT", "SELECT", "START", "UPDATE"]:
command = token.value
token_value = token.value.upper()
if token_value in ["BEGIN", "DELETE", "INSERT", "SELECT", "START", "UPDATE"]:
command = token_value
break
else:
command = None
3 changes: 3 additions & 0 deletions tests/sql.py
Original file line number Diff line number Diff line change
@@ -129,6 +129,9 @@ def test_rollback(self):
self.db.execute("ROLLBACK")
self.assertEqual(self.db.execute("SELECT val FROM cs50"), [])

def test_identifier_case(self):
self.assertIn("count", self.db.execute("SELECT 1 AS count")[0])

def tearDown(self):
self.db.execute("DROP TABLE cs50")
self.db.execute("DROP TABLE IF EXISTS foo")