lp bug: https://launchpad.net/bugs/314449 fixed
bzr revid: christophe@taupe-
20090131183618-pglu86hzq3ewsfxi
self.actions[id] = {'clean': False}
db = sql_db.db_connect('template1')
self.actions[id] = {'clean': False}
db = sql_db.db_connect('template1')
+ cr = db.serialized_cursor()
+ cr.autocommit(True) # XXX inhibit the effect of a serialized cursor. is it what we want ?
cr.execute('CREATE DATABASE "%s" ENCODING \'unicode\'' % db_name)
finally:
cr.close()
cr.execute('CREATE DATABASE "%s" ENCODING \'unicode\'' % db_name)
finally:
cr.close()
logger = netsvc.Logger()
db = sql_db.db_connect('template1')
logger = netsvc.Logger()
db = sql_db.db_connect('template1')
- cr = db.cursor()
- cr.autocommit(True)
+ cr = db.serialized_cursor()
+ cr.autocommit(True) # XXX inhibit the effect of a serialized cursor. is it what we want ?
try:
try:
cr.execute('DROP DATABASE "%s"' % db_name)
try:
try:
cr.execute('DROP DATABASE "%s"' % db_name)
raise Exception, "Database already exists"
db = sql_db.db_connect('template1')
raise Exception, "Database already exists"
db = sql_db.db_connect('template1')
- cr = db.cursor()
- cr.autocommit(True)
+ cr = db.serialized_cursor()
+ cr.autocommit(True) # XXX inhibit the effect of a serialized cursor. is it what we want ?
try:
cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE 'template0'""" % db_name)
finally:
try:
cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE 'template0'""" % db_name)
finally:
##############################################################################
import netsvc
##############################################################################
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
from psycopg2.pool import ThreadedConnectionPool
from psycopg2.psycopg1 import cursor as psycopg1cursor
return f(self, *args, **kwargs)
return wrapper
return f(self, *args, **kwargs)
return wrapper
- def __init__(self, pool):
+ def __init__(self, pool, serialized=False):
+ self._serialized = serialized
self._cnx = pool.getconn()
self._obj = self._cnx.cursor(cursor_factory=psycopg1cursor)
self.autocommit(False)
self._cnx = pool.getconn()
self._obj = self._cnx.cursor(cursor_factory=psycopg1cursor)
self.autocommit(False)
@check
def autocommit(self, on):
@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)])
def cursor(self):
return Cursor(self)
def cursor(self):
return Cursor(self)
+ def serialized_cursor(self):
+ return Cursor(self, True)
+
def __getattr__(self, name):
return getattr(self._pool, name)
def __getattr__(self, name):
return getattr(self._pool, name)