Skip to content

Commit

Permalink
added try-catch workaround for SQL.connect when sqlite3 is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
rongxin-liu committed Dec 2, 2022
1 parent 0c552d3 commit 3ccbd99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
package_dir={"": "src"},
packages=["cs50"],
url="https://github.com/cs50/python-cs50",
version="9.2.3"
version="9.2.4"
)
12 changes: 8 additions & 4 deletions src/cs50/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ def __init__(self, url, **kwargs):
def connect(dbapi_connection, connection_record):

# Enable foreign key constraints
if type(dbapi_connection) is sqlite3.Connection: # If back end is sqlite
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
cursor.close()
try:
if type(dbapi_connection) is sqlite3.Connection: # If back end is sqlite
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
cursor.close()
except:
# Temporary fix for missing sqlite3 module on the buildpack stack
pass

# Register listener
sqlalchemy.event.listen(self._engine, "connect", connect)
Expand Down

0 comments on commit 3ccbd99

Please sign in to comment.