mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-14679 dml/native_mysqli transactions support
This commit is contained in:
parent
fb76304b3b
commit
fa76662bb2
1 changed files with 41 additions and 0 deletions
|
@ -889,4 +889,45 @@ class mysqli_native_moodle_database extends moodle_database {
|
||||||
public function sql_regex($positivematch=true) {
|
public function sql_regex($positivematch=true) {
|
||||||
return $positivematch ? 'REGEXP' : 'NOT REGEXP';
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue