Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d5e442b

Browse files
authoredApr 8, 2020
Update sql.py
Functionality which commits changes to Postgres DB https://www.postgresql.org/docs/8.3/sql-commit.html
1 parent af0dea3 commit d5e442b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎src/cs50/sql.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ def shutdown_session(exception=None):
348348
try:
349349
result = connection.execute("SELECT LASTVAL()")
350350
ret = result.first()[0]
351+
352+
# Commit changes to Postgres
353+
connection.execute("COMMIT")
354+
351355
except sqlalchemy.exc.OperationalError: # If lastval is not yet defined in this session
352356
ret = None
353357
else:
@@ -356,6 +360,9 @@ def shutdown_session(exception=None):
356360
# If DELETE or UPDATE, return number of rows matched
357361
elif command in ["DELETE", "UPDATE"]:
358362
ret = result.rowcount
363+
# Commit changes to Postgres
364+
if self._engine.url.get_backend_name() in ["postgres", "postgresql"]:
365+
connection.execute("COMMIT")
359366

360367
# If constraint violated, return None
361368
except sqlalchemy.exc.IntegrityError as e:

0 commit comments

Comments
 (0)
Please sign in to comment.