Skip to content

Commit cc9199d

Browse files
committed
fixup! Fix prepared statement handling
1 parent e6d588f commit cc9199d

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

trino/dbapi.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -294,22 +294,13 @@ def warnings(self):
294294
return self._query.warnings
295295
return None
296296

297-
def _new_request_with_session_from(self, request):
298-
"""
299-
Returns a new request with the `ClientSession` set to the one from the
300-
given request.
301-
"""
302-
request = self.connection._create_request()
303-
request._client_session = request._client_session
304-
return request
305-
306297
def setinputsizes(self, sizes):
307298
raise trino.exceptions.NotSupportedError
308299

309300
def setoutputsize(self, size, column):
310301
raise trino.exceptions.NotSupportedError
311302

312-
def _prepare_statement(self, statement, name):
303+
def _prepare_statement(self, statement: str, name: str) -> None:
313304
"""
314305
Registers a prepared statement for the provided `operation` with the
315306
`name` assigned to it.
@@ -318,8 +309,7 @@ def _prepare_statement(self, statement, name):
318309
:param name: name that will be assigned to the prepared statement.
319310
"""
320311
sql = f"PREPARE {name} FROM {statement}"
321-
# TODO: Evaluate whether we can avoid the piggybacking on current request
322-
query = trino.client.TrinoQuery(self._new_request_with_session_from(self._request), sql=sql,
312+
query = trino.client.TrinoQuery(self.connection._create_request(), sql=sql,
323313
experimental_python_types=self._experimental_pyton_types)
324314
query.execute()
325315

@@ -404,10 +394,9 @@ def _format_prepared_param(self, param):
404394

405395
raise trino.exceptions.NotSupportedError("Query parameter of type '%s' is not supported." % type(param))
406396

407-
def _deallocate_prepared_statement(self, statement_name):
397+
def _deallocate_prepared_statement(self, statement_name: str) -> None:
408398
sql = 'DEALLOCATE PREPARE ' + statement_name
409-
# TODO: Evaluate whether we can avoid the piggybacking on current request
410-
query = trino.client.TrinoQuery(self._new_request_with_session_from(self._request), sql=sql,
399+
query = trino.client.TrinoQuery(self.connection._create_request(), sql=sql,
411400
experimental_python_types=self._experimental_pyton_types)
412401
query.execute()
413402

0 commit comments

Comments
 (0)