]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14679 dml/native_mysqli transactions support
authorskodak <skodak>
Mon, 27 Oct 2008 20:58:37 +0000 (20:58 +0000)
committerskodak <skodak>
Mon, 27 Oct 2008 20:58:37 +0000 (20:58 +0000)
lib/dml/mysqli_native_moodle_database.php

index b21f95c8234aa3572449d9f632b23ea2807ce4f6..1f95cf265cf5f017225f71f5ddd18318058fbe3a 100644 (file)
@@ -889,4 +889,45 @@ class mysqli_native_moodle_database extends moodle_database {
     public function sql_regex($positivematch=true) {
         return $positivematch ? 'REGEXP' : 'NOT REGEXP';
     }
+
+/// transactions
+    /**
+     * on DBs that support it, switch to transaction mode and begin a transaction
+     * you'll need to ensure you call commit_sql() or your changes *will* be lost.
+     *
+     * this is _very_ useful for massive updates
+     */
+    public function begin_sql() {
+        $result = $result = $this->mysqli->query("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED");
+        if ($result === false) {
+            return false;
+        }
+        $result = $result = $this->mysqli->query("BEGIN");
+        if ($result === false) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * on DBs that support it, commit the transaction
+     */
+    public function commit_sql() {
+        $result = $result = $this->mysqli->query("COMMIT");
+        if ($result === false) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * on DBs that support it, rollback the transaction
+     */
+    public function rollback_sql() {
+        $result = $result = $this->mysqli->query("ROLLBACK");
+        if ($result === false) {
+            return false;
+        }
+        return true;
+    }
 }