summaryrefslogtreecommitdiff
path: root/bin/sql_db.py
diff options
context:
space:
mode:
authorOlivier Laurent <olt@tinyerp.com>2009-02-03 15:53:08 +0100
committerOlivier Laurent <olt@tinyerp.com>2009-02-03 15:53:08 +0100
commit29c9b912e58e59362b355618b7cd6d84ba4336a4 (patch)
tree0f24c03ac0e37d3183d1af224caf9722094acca6 /bin/sql_db.py
parent8fb89ff578f8a58dbabbf5462c1ef71d09ed69d9 (diff)
parent7f28b06e6a7ad5124f69b4a3159e54a878b95a35 (diff)
[MERGE]
bzr revid: olt@tinyerp.com-20090203145308-j25zdhhz0g1xng73
Diffstat (limited to 'bin/sql_db.py')
-rw-r--r--bin/sql_db.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/bin/sql_db.py b/bin/sql_db.py
index b0212ac1ea4..ff9a6b0c2c6 100644
--- a/bin/sql_db.py
+++ b/bin/sql_db.py
@@ -21,7 +21,7 @@
##############################################################################
import netsvc
-from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_SERIALIZABLE
+from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_COMMITTED, ISOLATION_LEVEL_SERIALIZABLE
from psycopg2.pool import ThreadedConnectionPool
from psycopg2.psycopg1 import cursor as psycopg1cursor
@@ -76,8 +76,9 @@ class Cursor(object):
return f(self, *args, **kwargs)
return wrapper
- def __init__(self, pool):
+ def __init__(self, pool, serialized=False):
self._pool = pool
+ self._serialized = serialized
self._cnx = pool.getconn()
self._obj = self._cnx.cursor(cursor_factory=psycopg1cursor)
self.autocommit(False)
@@ -168,7 +169,8 @@ class Cursor(object):
@check
def autocommit(self, on):
- self._cnx.set_isolation_level([ISOLATION_LEVEL_SERIALIZABLE, ISOLATION_LEVEL_AUTOCOMMIT][bool(on)])
+ offlevel = [ISOLATION_LEVEL_READ_COMMITTED, ISOLATION_LEVEL_SERIALIZABLE][bool(self._serialized)]
+ self._cnx.set_isolation_level([offlevel, ISOLATION_LEVEL_AUTOCOMMIT][bool(on)])
@check
def commit(self):
@@ -190,6 +192,9 @@ class ConnectionPool(object):
def cursor(self):
return Cursor(self)
+ def serialized_cursor(self):
+ return Cursor(self, True)
+
def __getattr__(self, name):
return getattr(self._pool, name)