Skip to content

Commit

Permalink
fixup! Fix prepared statement handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hashhar committed Oct 3, 2022
1 parent e6d588f commit cc9199d
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions trino/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,13 @@ def warnings(self):
return self._query.warnings
return None

def _new_request_with_session_from(self, request):
"""
Returns a new request with the `ClientSession` set to the one from the
given request.
"""
request = self.connection._create_request()
request._client_session = request._client_session
return request

def setinputsizes(self, sizes):
raise trino.exceptions.NotSupportedError

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

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

Expand Down Expand Up @@ -404,10 +394,9 @@ def _format_prepared_param(self, param):

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

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

Expand Down

0 comments on commit cc9199d

Please sign in to comment.