MDL-17020 dml: native pgsql driver - implementation and unittests of transactions
This commit is contained in:
@@ -1036,4 +1036,47 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
return $positivematch ? '~*' : '!~*';
|
||||
}
|
||||
|
||||
/// 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() {
|
||||
$sql = "BEGIN ISOLATION LEVEL READ COMMITTED";
|
||||
$result = pg_query($this->pgsql, $sql);
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
pg_free_result($result);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* on DBs that support it, commit the transaction
|
||||
*/
|
||||
public function commit_sql() {
|
||||
$sql = "COMMIT";
|
||||
$result = pg_query($this->pgsql, $sql);
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
pg_free_result($result);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* on DBs that support it, rollback the transaction
|
||||
*/
|
||||
public function rollback_sql() {
|
||||
$sql = "ROLLBACK";
|
||||
$result = pg_query($this->pgsql, $sql);
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
pg_free_result($result);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user