disabled logging, removed temporary prints, removed support for multiple statements by dmalan · Pull Request #26 · cs50/python-cs50 · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 19 additions & 12 deletions .travis.yml
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"Topic :: Software Development :: Libraries :: Python Modules"
],
description="CS50 library for Python",
install_requires=["SQLAlchemy"],
install_requires=["SQLAlchemy", "sqlparse"],
keywords="cs50",
name="cs50",
package_dir={"": "src"},
packages=["cs50"],
url="https://github.com/cs50/python-cs50",
version="2.0.0"
version="2.1.0"
)
7 changes: 6 additions & 1 deletion src/cs50/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import re
import sqlalchemy
import sqlparse
import sys
import warnings

Expand Down Expand Up @@ -86,6 +87,10 @@ def process(value):
else:
return process(value)

# allow only one statement at a time
if len(sqlparse.split(text)) > 1:
raise RuntimeError("too many statements at once")

# raise exceptions for warnings
warnings.filterwarnings("error")

Expand Down Expand Up @@ -123,7 +128,7 @@ def process(value):

# if INSERT, return primary key value for a newly inserted row
elif re.search(r"^\s*INSERT\s+", statement, re.I):
if self.engine.url.get_backend_name() == "postgresql":
if self.engine.url.get_backend_name() in ["postgres", "postgresql"]:
result = self.engine.execute(sqlalchemy.text("SELECT LASTVAL()"))
return result.first()[0]
else:
Expand Down
18 changes: 7 additions & 11 deletions tests/sqltests.py