@@ -100,7 +100,7 @@ def connect(dbapi_connection, connection_record):
100
100
self ._logger .disabled = True
101
101
try :
102
102
connection = self ._engine .connect ()
103
- connection .execute ("SELECT 1" )
103
+ connection .execute (sqlalchemy . text ( "SELECT 1" ) )
104
104
connection .close ()
105
105
except sqlalchemy .exc .OperationalError as e :
106
106
e = RuntimeError (_parse_exception (e ))
@@ -153,10 +153,10 @@ def execute(self, sql, *args, **kwargs):
153
153
full_statement = ' ' .join (str (token ) for token in statements [0 ].tokens if token .ttype in [sqlparse .tokens .Keyword , sqlparse .tokens .Keyword .DDL , sqlparse .tokens .Keyword .DML ])
154
154
full_statement = full_statement .upper ()
155
155
156
- # set of possible commands
156
+ # Set of possible commands
157
157
commands = {"BEGIN" , "CREATE VIEW" , "DELETE" , "INSERT" , "SELECT" , "START" , "UPDATE" }
158
158
159
- # check if the full_statement starts with any command
159
+ # Check if the full_statement starts with any command
160
160
command = next ((cmd for cmd in commands if full_statement .startswith (cmd )), None )
161
161
162
162
# Flatten statement
@@ -344,7 +344,7 @@ def teardown_appcontext(exception):
344
344
if command == "SELECT" :
345
345
346
346
# Coerce types
347
- rows = [dict (row ) for row in result .fetchall ()]
347
+ rows = [dict (row ) for row in result .mappings (). all ()]
348
348
for row in rows :
349
349
for column in row :
350
350
@@ -370,7 +370,7 @@ def teardown_appcontext(exception):
370
370
# "(psycopg2.errors.ObjectNotInPrerequisiteState) lastval is not yet defined in this session",
371
371
# a la https://stackoverflow.com/a/24186770/5156190;
372
372
# cf. https://www.psycopg.org/docs/errors.html re 55000
373
- result = connection .execute ("""
373
+ result = connection .execute (sqlalchemy . text ( """
374
374
CREATE OR REPLACE FUNCTION _LASTVAL()
375
375
RETURNS integer LANGUAGE plpgsql
376
376
AS $$
@@ -382,7 +382,7 @@ def teardown_appcontext(exception):
382
382
END;
383
383
END $$;
384
384
SELECT _LASTVAL();
385
- """ )
385
+ """ ))
386
386
ret = result .first ()[0 ]
387
387
388
388
# If not PostgreSQL
0 commit comments