begin_sql() now uses current storage engine info to know if transactions are going...
authorstronk7 <stronk7>
Wed, 9 Sep 2009 16:01:31 +0000 (16:01 +0000)
committerstronk7 <stronk7>
Wed, 9 Sep 2009 16:01:31 +0000 (16:01 +0000)
(only InnoDB detected as trasaction-able)

lib/dml/mysqli_native_moodle_database.php

index 90e51c0b161c6cc567ec624dc3450cd2093694ee..1aa094b83a43f39412745e5fffc9848354024867 100644 (file)
@@ -1028,15 +1028,30 @@ class mysqli_native_moodle_database extends moodle_database {
      * this is _very_ useful for massive updates
      */
     public function begin_sql() {
+        // Only will accept transactions if using InnoDB storage engine (more engines can be added easily BDB, Falcon...)
+        $sql = "SELECT @@storage_engine";
+        $this->query_start($sql, NULL, SQL_QUERY_AUX);
+        $result = $this->mysqli->query($sql);
+        $this->query_end($result);
+        if ($rec = $result->fetch_assoc()) {
+            if (!in_array($rec['@@storage_engine'], array('InnoDB'))) {
+                return false;
+            }
+        } else {
+            return false;
+        }
+        $result->close();
+
         if (!parent::begin_sql()) {
             return false;
         }
+
         $sql = "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED";
         $this->query_start($sql, NULL, SQL_QUERY_AUX);
         $result = $this->mysqli->query($sql);
         $this->query_end($result);
 
-        $sql = "BEGIN";
+        $sql = "START TRANSACTION";
         $this->query_start($sql, NULL, SQL_QUERY_AUX);
         $result = $this->mysqli->query($sql);
         $this->query_end($result);