summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/sqlite/pysqlite.py
diff options
context:
space:
mode:
authorGord Thompson <gord@gordthompson.com>2020-02-22 06:44:05 -0700
committerGord Thompson <gord@gordthompson.com>2020-03-24 12:15:02 -0600
commit64e8303debd8064d7d9c01c3300cca5f54c02db1 (patch)
tree4d2953bc2a5f31bc8b16ef9788914185caa8d9df /lib/sqlalchemy/dialects/sqlite/pysqlite.py
parente6b6ec78e6d6f96537eaf542f469a7e88134e9fc (diff)
downloadsqlalchemy-64e8303debd8064d7d9c01c3300cca5f54c02db1.tar.gz
Implement autocommit isolation level for pysqlite
Fixes: #5164 Change-Id: I190b9de552dfed9f2a33babf82e42465ef09c82a
Diffstat (limited to 'lib/sqlalchemy/dialects/sqlite/pysqlite.py')
-rw-r--r--lib/sqlalchemy/dialects/sqlite/pysqlite.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py
index b8a42a506..807f9488d 100644
--- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py
+++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py
@@ -324,6 +324,12 @@ ourselves. This is achieved using two event listeners::
# emit our own BEGIN
conn.exec_driver_sql("BEGIN")
+.. warning:: When using the above recipe, it is advised to not use the
+ :paramref:`.execution_options.isolation_level` setting on
+ :class:`.Connection` and :func:`.create_engine` with the SQLite driver,
+ as this function necessarily will also alter the ".isolation_level" setting.
+
+
Above, we intercept a new pysqlite connection and disable any transactional
integration. Then, at the point at which SQLAlchemy knows that transaction
scope is to begin, we emit ``"BEGIN"`` ourselves.
@@ -437,6 +443,20 @@ class SQLiteDialect_pysqlite(SQLiteDialect):
def _get_server_version_info(self, connection):
return self.dbapi.sqlite_version_info
+ def set_isolation_level(self, connection, level):
+ if hasattr(connection, "connection"):
+ dbapi_connection = connection.connection
+ else:
+ dbapi_connection = connection
+
+ if level == "AUTOCOMMIT":
+ dbapi_connection.isolation_level = None
+ else:
+ dbapi_connection.isolation_level = ""
+ return super(SQLiteDialect_pysqlite, self).set_isolation_level(
+ connection, level
+ )
+
def create_connect_args(self, url):
if url.username or url.password or url.host or url.port:
raise exc.ArgumentError(