[sqlalchemy-20] Use Connection.execute() instead of Engine.execute()

According to the SLQAlchemy documentation, "the Engine.execute() method
is considered legacy as of the 1.x series of SQLAlchemy and will be
removed in 2.0. All statement execution in SQLAlchemy 2.0 is performed
by the Connection.execute() method of Connection, or in the ORM by the
Session.execute() method of Session."

Change-Id: Ic4d7a0740f7136cac2055e57e57f66e76cb150f3
Closes-Bug: #2008223
This commit is contained in:
Rodolfo Alonso Hernandez 2023-02-18 14:50:58 +01:00 committed by Rodolfo Alonso
parent 23fa6b3c2f
commit 444cec2ba0

View File

@ -100,13 +100,10 @@ class _EnableSQLiteFKsFixture(fixtures.Fixture):
def _setUp(self):
if self.engine.name == 'sqlite':
self.engine.execute("PRAGMA foreign_keys=ON")
def disable_fks():
with self.engine.connect() as conn:
conn.connection.rollback()
conn.execute("PRAGMA foreign_keys=OFF")
self.addCleanup(disable_fks)
with self.engine.connect() as conn:
cursor = conn.connection.cursor()
cursor.execute('PRAGMA foreign_keys=ON')
cursor.close()
class SqlFixture(fixtures.Fixture):