MDL-17020 dml: native pgsql driver - implementation and unittests of transactions

This commit is contained in:
skodak
2008-10-27 20:21:04 +00:00
parent 0bd364c1d7
commit fb76304b3b
3 changed files with 109 additions and 3 deletions
+43
View File
@@ -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;
}
}