Commit cd196702 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Do not commit the current transaction then begin another when calling setXXX()...

Do not commit the current transaction then begin another when calling setXXX() methods from a transaction.
This avoid commit partial queries that may put the relational database in a inconsistent state (eg. a new partition table but not the last PTID).

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1380 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 7845f37c
...@@ -85,6 +85,18 @@ class DatabaseManager(object): ...@@ -85,6 +85,18 @@ class DatabaseManager(object):
""" """
Set a configuration value Set a configuration value
""" """
if self._under_transaction:
self._setConfiguration(key, value)
else:
self.begin()
try:
self._setConfiguration(key, value)
except:
self.rollback()
raise
self.commit()
def _setConfiguration(self, key, value):
raise NotImplementedError raise NotImplementedError
def getUUID(self): def getUUID(self):
......
...@@ -175,18 +175,12 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -175,18 +175,12 @@ class MySQLDatabaseManager(DatabaseManager):
except IndexError: except IndexError:
return None return None
def setConfiguration(self, key, value): def _setConfiguration(self, key, value):
self.begin() q = self.query
try: e = self.escape
q = self.query key = e(str(key))
e = self.escape value = e(str(value))
key = e(str(key)) q("""REPLACE INTO config VALUES ('%s', '%s')""" % (key, value))
value = e(str(value))
q("""REPLACE INTO config VALUES ('%s', '%s')""" % (key, value))
except:
self.rollback()
raise
self.commit()
def getPartitionTable(self): def getPartitionTable(self):
q = self.query q = self.query
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment