Add an extension hook for error reporting.
[platal.git] / classes / xdb.php
index c353f54..dd23938 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -194,8 +194,13 @@ class XDB
         return self::run($query);
     }
 
+    private static $inTransaction = false;
     public static function startTransaction()
     {
+        if (self::$inTransaction) {
+            throw new XDBException('START TRANSACTION', 'Already in a transaction');
+        }
+        self::$inTransaction = true;
         self::rawExecute('SET AUTOCOMMIT = 0');
         self::rawExecute('START TRANSACTION');
     }
@@ -204,12 +209,14 @@ class XDB
     {
         self::rawExecute('COMMIT');
         self::rawExecute('SET AUTOCOMMIT = 1');
+        self::$inTransaction = false;
     }
 
     public static function rollback()
     {
         self::rawExecute('ROLLBACK');
         self::rawExecute('SET AUTOCOMMIT = 1');
+        self::$inTransaction = false;
     }
 
     public static function runTransactionV($callback, array $args)
@@ -238,7 +245,7 @@ class XDB
     {
         $args = func_get_args();
         $cb = array_shift($args);
-        self::runTransactionV($cb, $args);
+        return self::runTransactionV($cb, $args);
     }
 
     public static function iterator()