From 66e0a7771f66b352e6712cf2d71936c6f8238617 Mon Sep 17 00:00:00 2001 From: Tony Locke Date: Wed, 14 May 2014 14:36:08 +0100 Subject: Autocommit isolation level for postgresql+pg8000 As with postgresql+psycopg2, execution_options(isolation_level='AUTOCOMMIT') now works for the postgresql+pg8000 dialect. Also enabled the autocommit test in test_dialect.py for pg8000. --- lib/sqlalchemy/dialects/postgresql/pg8000.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 788bfc5c8..27b867b09 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -121,4 +121,28 @@ class PGDialect_pg8000(PGDialect): def is_disconnect(self, e, connection, cursor): return "connection is closed" in str(e) + def set_isolation_level(self, connection, level): + level = level.replace('_', ' ') + print("level is", level) + print("autocommit is", connection.autocommit) + print("class is", connection) + + if level == 'AUTOCOMMIT': + connection.connection.autocommit = True + elif level in self._isolation_lookup: + connection.connection.autocommit = False + cursor = connection.cursor() + cursor.execute( + "SET SESSION CHARACTERISTICS AS TRANSACTION " + "ISOLATION LEVEL %s" % level) + cursor.execute("COMMIT") + cursor.close() + else: + raise exc.ArgumentError( + "Invalid value '%s' for isolation_level. " + "Valid isolation levels for %s are %s or AUTOCOMMIT" % + (level, self.name, ", ".join(self._isolation_lookup)) + ) + print("autocommit is now", connection.autocommit) + dialect = PGDialect_pg8000 -- cgit v1.2.1