This PR enables GN2 to support roll-backs should anything wrong happen within a connection context (as opposed to the cursor context). For an overview of how context managers - the inspiration behind this PR - please look at: https://www.youtube.com/watch?v=ucGpcA9r4hU
To control roll-backs, we need to:
set autocommit=0
have a table whose engine supports transactions .E.g. innodb. ATM, GN2 uses MyISAM which is a relic of the past.
Regardless of what engine we use, this PR has no bad side-effect and there's no code changes else where that's required.
How should this be tested?
Example usage:
Assuming InnoDB:
with database_connection() as conn:
with conn.cursor() as cursor:
cursor.execute(
"""
INSERT INTO CaseAttribute (Name, Description) VALUES (%s, %s)
""", ("Test", "Random Description")
)
print(cursor.fetchall())
print(0/0)
The above query will be rolled back. On MyISAM and other db engines that don't have transactional support, the above will still be executed and "connection.rollback()" will be silently ignored.
Description
This PR enables GN2 to support roll-backs should anything wrong happen within a connection context (as opposed to the cursor context). For an overview of how context managers - the inspiration behind this PR - please look at: https://www.youtube.com/watch?v=ucGpcA9r4hU
To control roll-backs, we need to:
Regardless of what engine we use, this PR has no bad side-effect and there's no code changes else where that's required.
How should this be tested?
Example usage: Assuming InnoDB:
The above query will be rolled back. On MyISAM and other db engines that don't have transactional support, the above will still be executed and "connection.rollback()" will be silently ignored.