Skip to content

Commit

Permalink
Use EXECUTE IMMEDIATE for parameterized statement executions
Browse files Browse the repository at this point in the history
  • Loading branch information
aalbu committed May 23, 2023
1 parent dc54d46 commit 75b013a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions trino/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __repr__(self):
return f"LRUCache(capacity: {self.capacity}, ttl: {self.ttl_seconds} seconds, {self.cache})"


mustUseLegacyPreparedStatements = TimeBoundLRUCache(1024, 3600)
must_use_legacy_prepared_statements = TimeBoundLRUCache(1024, 3600)


def connect(*args, **kwargs):
Expand Down Expand Up @@ -276,7 +276,7 @@ def _use_legacy_prepared_statements(self):
if self.legacy_prepared_statements is not None:
return self.legacy_prepared_statements

value = mustUseLegacyPreparedStatements.get((self.host, self.port))
value = must_use_legacy_prepared_statements.get((self.host, self.port))
if value is None:
try:
query = trino.client.TrinoQuery(
Expand All @@ -287,10 +287,13 @@ def _use_legacy_prepared_statements(self):
if rows:
version = rows[0][0]
value = (version <= "417")
mustUseLegacyPreparedStatements.put((self.host, self.port), value)
except Exception:
# not updating the cache
must_use_legacy_prepared_statements.put((self.host, self.port), value)
except Exception as e:
logger.warning(
"Prepared statement mode auto-detection failed for %s:%s; defaulting to legacy mode - %s",
self.host, self.port, e)
value = True
must_use_legacy_prepared_statements.put((self.host, self.port), value)
return value


Expand Down

0 comments on commit 75b013a

Please sign in to comment.