Skip to content

Support execute chaining #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/integration/test_dbapi_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,11 @@ def test_select_cursor_iteration(trino_connection):
assert sorted(rows0) == sorted(rows1)


def test_execute_chaining(trino_connection):
cur = trino_connection.cursor()
assert cur.execute('SELECT 1').fetchone()[0] == 1


def test_select_query_no_result(trino_connection):
cur = trino_connection.cursor()
cur.execute("SELECT * FROM system.runtime.nodes WHERE false")
Expand Down
8 changes: 4 additions & 4 deletions trino/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def execute(self, operation, params=None):
self._query = self._execute_prepared_statement(
statement_name, params
)
result = self._query.execute()
self._iterator = iter(self._query.execute())
finally:
# Send deallocate statement
# At this point the query can be deallocated since it has already
Expand All @@ -456,9 +456,8 @@ def execute(self, operation, params=None):
else:
self._query = trino.client.TrinoQuery(self._request, sql=operation,
legacy_primitive_types=self._legacy_primitive_types)
result = self._query.execute()
self._iterator = iter(result)
return result
self._iterator = iter(self._query.execute())
return self

def executemany(self, operation, seq_of_params):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency do we also want it for executemany?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added for consistency

"""
Expand All @@ -485,6 +484,7 @@ def executemany(self, operation, seq_of_params):
self.execute(operation, seq_of_params[-1])
else:
self.execute(operation)
return self

def fetchone(self) -> Optional[List[Any]]:
"""
Expand Down