Skip to content

Commit fd78e41

Browse files
damian3031hashhar
authored andcommitted
Support execute chaining
1 parent a6b1eed commit fd78e41

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

tests/integration/test_dbapi_integration.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,11 @@ def test_select_cursor_iteration(trino_connection):
785785
assert sorted(rows0) == sorted(rows1)
786786

787787

788+
def test_execute_chaining(trino_connection):
789+
cur = trino_connection.cursor()
790+
assert cur.execute('SELECT 1').fetchone()[0] == 1
791+
792+
788793
def test_select_query_no_result(trino_connection):
789794
cur = trino_connection.cursor()
790795
cur.execute("SELECT * FROM system.runtime.nodes WHERE false")

trino/dbapi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def execute(self, operation, params=None):
445445
self._query = self._execute_prepared_statement(
446446
statement_name, params
447447
)
448-
result = self._query.execute()
448+
self._iterator = iter(self._query.execute())
449449
finally:
450450
# Send deallocate statement
451451
# At this point the query can be deallocated since it has already
@@ -456,9 +456,8 @@ def execute(self, operation, params=None):
456456
else:
457457
self._query = trino.client.TrinoQuery(self._request, sql=operation,
458458
legacy_primitive_types=self._legacy_primitive_types)
459-
result = self._query.execute()
460-
self._iterator = iter(result)
461-
return result
459+
self._iterator = iter(self._query.execute())
460+
return self
462461

463462
def executemany(self, operation, seq_of_params):
464463
"""
@@ -485,6 +484,7 @@ def executemany(self, operation, seq_of_params):
485484
self.execute(operation, seq_of_params[-1])
486485
else:
487486
self.execute(operation)
487+
return self
488488

489489
def fetchone(self) -> Optional[List[Any]]:
490490
"""

0 commit comments

Comments
 (0)