diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-16 17:04:07 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-16 17:04:07 -0500 |
commit | 7325ba60bce50c63ce83fcb44f6b337664262ad0 (patch) | |
tree | 3ead541a555e1fda9f57173ab836d60334a9e3b1 /lib/sqlalchemy/dialects/postgresql/psycopg2.py | |
parent | 8259e2fd2bb183bdcbc019bd03a281f411c80307 (diff) | |
download | sqlalchemy-7325ba60bce50c63ce83fcb44f6b337664262ad0.tar.gz |
- execution_options() on Connection accepts
"isolation_level" argument, sets transaction isolation
level for that connection only until returned to the
connection pool, for thsoe backends which support it
(SQLite, Postgresql) [ticket:2001]
- disallow the option on Engine (use isolation_level to create_engine()),
Executable (we don't want to check/set per statement)
- docs
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/psycopg2.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 806ba41f8..21ce1211a 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -79,13 +79,19 @@ The psycopg2 dialect will log Postgresql NOTICE messages via the logging.getLogger('sqlalchemy.dialects.postgresql').setLevel(logging.INFO) -Per-Statement Execution Options -------------------------------- - -The following per-statement execution options are respected: - -* *stream_results* - Enable or disable usage of server side cursors for the SELECT-statement. - If *None* or not set, the *server_side_cursors* option of the connection is used. If +Per-Statement/Connection Execution Options +------------------------------------------- + +The following DBAPI-specific options are respected when used with +:meth:`.Connection.execution_options`, :meth:`.Executable.execution_options`, +:meth:`.Query.execution_options`, in addition to those not specific to DBAPIs: + +* isolation_level - Set the transaction isolation level for the lifespan of a + :class:`.Connection` (can only be set on a connection, not a statement or query). + This includes the options ``SERIALIZABLE``, ``READ COMMITTED``, + ``READ UNCOMMITTED`` and ``REPEATABLE READ``. +* stream_results - Enable or disable usage of server side cursors. + If ``None`` or not set, the ``server_side_cursors`` option of the :class:`.Engine` is used. If auto-commit is enabled, the option is ignored. """ @@ -247,20 +253,20 @@ class PGDialect_psycopg2(PGDialect): def _isolation_lookup(self): extensions = __import__('psycopg2.extensions').extensions return { - 'READ_COMMITTED':extensions.ISOLATION_LEVEL_READ_COMMITTED, - 'READ_UNCOMMITTED':extensions.ISOLATION_LEVEL_READ_UNCOMMITTED, - 'REPEATABLE_READ':extensions.ISOLATION_LEVEL_REPEATABLE_READ, + 'READ COMMITTED':extensions.ISOLATION_LEVEL_READ_COMMITTED, + 'READ UNCOMMITTED':extensions.ISOLATION_LEVEL_READ_UNCOMMITTED, + 'REPEATABLE READ':extensions.ISOLATION_LEVEL_REPEATABLE_READ, 'SERIALIZABLE':extensions.ISOLATION_LEVEL_SERIALIZABLE } def set_isolation_level(self, connection, level): try: - level = self._isolation_lookup[level.replace(' ', '_')] + level = self._isolation_lookup[level.replace('_', ' ')] except KeyError: raise exc.ArgumentError( "Invalid value '%s' for isolation_level. " "Valid isolation levels for %s are %s" % - (self.name, level, ", ".join(self._isolation_lookup)) + (level, self.name, ", ".join(self._isolation_lookup)) ) connection.set_isolation_level(level) |