Add XDB::startTransaction(), XDB::commit() and XDB::rollback().
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 7 Oct 2010 11:54:05 +0000 (13:54 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 7 Oct 2010 11:54:05 +0000 (13:54 +0200)
Note: you should always use these functions when using transactions since
they perform the necessary post/pre actions to ensure the environment is
well configured.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/xdb.php

index 2265e41..28010c9 100644 (file)
@@ -86,7 +86,7 @@ class XDB
 
         if ($globals->debug & DEBUG_BT) {
             $explain = array();
-            if (strpos($query, 'FOUND_ROWS()') === false) {
+            if (strpos($query, 'FOUND_ROWS()') === false && strpos($query, 'AUTOCOMMIT') === false) {
                 $res = self::$mysqli->query("EXPLAIN $query");
                 if ($res) {
                     while ($row = $res->fetch_assoc()) {
@@ -194,6 +194,24 @@ class XDB
         return self::run($query);
     }
 
+    public static function startTransaction()
+    {
+        self::rawExecute('SET AUTOCOMMIT = 0');
+        self::rawExecute('START TRANSACTION');
+    }
+
+    public static function commit()
+    {
+        self::rawExecute('COMMIT');
+        self::rawExecute('SET AUTOCOMMIT = 1');
+    }
+
+    public static function rollback()
+    {
+        self::rawExecute('ROLLBACK');
+        self::rawExecute('SET AUTOCOMMIT = 1');
+    }
+
     public static function iterator()
     {
         return new XDBIterator(self::prepare(func_get_args()));