summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/pg8000.py
diff options
context:
space:
mode:
authorTony Locke <tlocke@tlocke.org.uk>2014-05-14 14:36:08 +0100
committerTony Locke <tlocke@tlocke.org.uk>2014-05-22 20:13:10 +0100
commit66e0a7771f66b352e6712cf2d71936c6f8238617 (patch)
treeb9dd5d79d34bfae3017c5180ee6624180fa80095 /lib/sqlalchemy/dialects/postgresql/pg8000.py
parent32bae567fe487ca78d23d775792e6dbd7657ba53 (diff)
downloadsqlalchemy-66e0a7771f66b352e6712cf2d71936c6f8238617.tar.gz
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.
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/pg8000.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pg8000.py24
1 files changed, 24 insertions, 0 deletions
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