]> git.jsancho.org Git - mojodb.git/blobdiff - MySQL.py
Savepoints to protect integrity of documents
[mojodb.git] / MySQL.py
index e983a670fa957f2d082f21b6c41a729512a05716..03969f78c5add49964e417498a6d56bc11dcb637 100644 (file)
--- a/MySQL.py
+++ b/MySQL.py
@@ -84,9 +84,10 @@ class Connection(connection.Connection):
     Constraint = Constraint
     Literal = Literal
 
-    def __init__(self, *args, **kwargs):
-        self._db_con = MySQLdb.connect(*args, **kwargs)
-        self._db_con_autocommit = MySQLdb.connect(*args, **kwargs)
+    def __init__(self, host="localhost", user="", passwd="", *args, **kwargs):
+        self._db_con = MySQLdb.connect(host=host, user=user, passwd=passwd)
+        self._db_con_autocommit = MySQLdb.connect(host=host, user=user, passwd=passwd)
+        super(Connection, self).__init__(*args, **kwargs)
 
     def query(self, sql, db=None):
         if db is None:
@@ -170,3 +171,15 @@ class Connection(connection.Connection):
 
     def rollback(self):
         self._db_con.rollback()
+
+    def savepoint(self, name):
+        self.execute("SAVEPOINT %s" % name)
+        return True
+
+    def commit_savepoint(self, name):
+        self.execute("RELEASE SAVEPOINT %s" % name)
+        return True
+
+    def rollback_savepoint(self, name):
+        self.execute("ROLLBACK TO %s" % name)
+        return True