Skip to content

Commit

Permalink
feat: autocommit statements
Browse files Browse the repository at this point in the history
  • Loading branch information
dungdm93 committed Apr 26, 2021
1 parent 8abfc0a commit bfdfc05
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions trino/sqlalchemy/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from trino import dbapi as trino_dbapi
from trino.auth import BasicAuthentication
from trino.dbapi import Cursor

from . import compiler, datatype, error

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

def do_execute(self, cursor: Cursor, statement: str, parameters: Tuple[Any, ...],
context: DefaultExecutionContext = None):
cursor.execute(statement, parameters)
if context and context.should_autocommit:
# SQL statement only submitted to Trino server when cursor.fetch*() is called.
# For DDL (CREATE/ALTER/DROP) and DML (INSERT/UPDATE/DELETE) statement, call cursor.description
# to force submit statement immediately.
cursor.description

def do_rollback(self, dbapi_connection):
if dbapi_connection.transaction is not None:
dbapi_connection.rollback()
Expand Down

0 comments on commit bfdfc05

Please sign in to comment.