summaryrefslogtreecommitdiff
path: root/bin/sql_db.py
diff options
context:
space:
mode:
authorChristophe Simonis <christophe@taupe>2009-01-31 19:36:18 +0100
committerChristophe Simonis <christophe@taupe>2009-01-31 19:36:18 +0100
commit9c721d3090d41f25da4a93afcfe46822e0350224 (patch)
tree0cecee343f4aa5d83069486a571664dc0c8cbdca /bin/sql_db.py
parent27240361ca5ead2597ae8f0c63043bab0e969001 (diff)
[FIX] database connections aren't serialized by default
lp bug: https://launchpad.net/bugs/314449 fixed bzr revid: christophe@taupe-20090131183618-pglu86hzq3ewsfxi
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)