@@ -272,7 +272,7 @@ async def _get_statement(self, query, timeout, *, named: bool=False):
272
272
# Only use the cache when:
273
273
# * `statement_cache_size` is greater than 0;
274
274
# * query size is less than `max_cacheable_statement_size`.
275
- use_cache = cache_enabled = self ._stmt_cache .get_max_size () > 0
275
+ use_cache = self ._stmt_cache .get_max_size () > 0
276
276
if (use_cache and
277
277
self ._config .max_cacheable_statement_size and
278
278
len (query ) > self ._config .max_cacheable_statement_size ):
@@ -286,13 +286,13 @@ async def _get_statement(self, query, timeout, *, named: bool=False):
286
286
statement = await self ._protocol .prepare (stmt_name , query , timeout )
287
287
ready = statement ._init_types ()
288
288
if ready is not True :
289
- types = await self .__execute (self . _intro_query , ( list ( ready ),),
290
- 0 , timeout )
289
+ types , intro_stmt = await self .__execute (
290
+ self . _intro_query , ( list ( ready ),), 0 , timeout )
291
291
self ._protocol .get_settings ().register_data_types (types )
292
- if not cache_enabled :
293
- # The execution of the introspection query with statement
294
- # cache turned off has blown away the anonymous statement
295
- # we've prepared for the query, so we need to re-prepare it.
292
+ if not intro_stmt . name and not statement . name :
293
+ # The introspection query has used an anonymous statement,
294
+ # which has blown away the anonymous statement we've prepared
295
+ # for the query, so we need to re-prepare it.
296
296
statement = await self ._protocol .prepare (
297
297
stmt_name , query , timeout )
298
298
@@ -1199,8 +1199,9 @@ def _drop_global_statement_cache(self):
1199
1199
1200
1200
async def _execute (self , query , args , limit , timeout , return_status = False ):
1201
1201
with self ._stmt_exclusive_section :
1202
- return await self .__execute (query , args , limit , timeout ,
1203
- return_status = return_status )
1202
+ result , _ = await self .__execute (
1203
+ query , args , limit , timeout , return_status = return_status )
1204
+ return result
1204
1205
1205
1206
async def __execute (self , query , args , limit , timeout ,
1206
1207
return_status = False ):
@@ -1214,7 +1215,8 @@ async def _executemany(self, query, args, timeout):
1214
1215
stmt , args , '' , timeout )
1215
1216
timeout = self ._protocol ._get_timeout (timeout )
1216
1217
with self ._stmt_exclusive_section :
1217
- return await self ._do_execute (query , executor , timeout )
1218
+ result , _ = await self ._do_execute (query , executor , timeout )
1219
+ return result
1218
1220
1219
1221
async def _do_execute (self , query , executor , timeout , retry = True ):
1220
1222
if timeout is None :
@@ -1263,10 +1265,10 @@ async def _do_execute(self, query, executor, timeout, retry=True):
1263
1265
if self ._protocol .is_in_transaction () or not retry :
1264
1266
raise
1265
1267
else :
1266
- result = await self ._do_execute (
1268
+ return await self ._do_execute (
1267
1269
query , executor , timeout , retry = False )
1268
1270
1269
- return result
1271
+ return result , stmt
1270
1272
1271
1273
1272
1274
async def connect (dsn = None , * ,
0 commit comments