|
14 | 14 |
|
15 | 15 | from sqlalchemy import exc, sql
|
16 | 16 | from sqlalchemy.engine.base import Connection
|
17 |
| -from sqlalchemy.engine.default import DefaultDialect |
| 17 | +from sqlalchemy.engine.default import DefaultDialect, DefaultExecutionContext |
18 | 18 | from sqlalchemy.engine.url import URL
|
19 | 19 |
|
20 | 20 | from trino import dbapi as trino_dbapi
|
21 | 21 | from trino.auth import BasicAuthentication
|
| 22 | +from trino.dbapi import Cursor |
22 | 23 |
|
23 | 24 | from . import compiler, datatype, error
|
24 | 25 |
|
@@ -260,6 +261,15 @@ def _get_default_schema_name(self, connection: Connection) -> Optional[str]:
|
260 | 261 | dbapi_connection: trino_dbapi.Connection = connection.connection
|
261 | 262 | return dbapi_connection.schema
|
262 | 263 |
|
| 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 | + |
263 | 273 | def do_rollback(self, dbapi_connection):
|
264 | 274 | if dbapi_connection.transaction is not None:
|
265 | 275 | dbapi_connection.rollback()
|
|
0 commit comments