Skip to content

Commit f448713

Browse files
committed
feat: autocommit statements
1 parent 8abfc0a commit f448713

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

trino/sqlalchemy/dialect.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
from sqlalchemy import exc, sql
1616
from sqlalchemy.engine.base import Connection
17-
from sqlalchemy.engine.default import DefaultDialect
17+
from sqlalchemy.engine.default import DefaultDialect, DefaultExecutionContext
1818
from sqlalchemy.engine.url import URL
1919

2020
from trino import dbapi as trino_dbapi
2121
from trino.auth import BasicAuthentication
22+
from trino.dbapi import Cursor
2223

2324
from . import compiler, datatype, error
2425

@@ -260,6 +261,15 @@ def _get_default_schema_name(self, connection: Connection) -> Optional[str]:
260261
dbapi_connection: trino_dbapi.Connection = connection.connection
261262
return dbapi_connection.schema
262263

264+
def do_execute(self, cursor: Cursor, statement: str, parameters: Tuple[Any, ...],
265+
context: DefaultExecutionContext = None):
266+
cursor.execute(statement, parameters)
267+
if context and context.should_autocommit:
268+
# SQL statement only submitted to Trino server when cursor.fetch*() is called.
269+
# For DDL (CREATE/ALTER/DROP) and DML (INSERT/UPDATE/DELETE) statement, call cursor.description
270+
# to force submit statement immediately.
271+
cursor.description # noqa
272+
263273
def do_rollback(self, dbapi_connection):
264274
if dbapi_connection.transaction is not None:
265275
dbapi_connection.rollback()

0 commit comments

Comments
 (0)