Merge pull request #39 from dhensby/pulls/2.0/nested-transactions

FIX Add nested transaction support
This commit is contained in:
Damian Mooyman 2018-03-13 09:25:09 +13:00 committed by GitHub
commit a38ab53e33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 3 deletions

View File

@ -60,6 +60,11 @@ class SQLite3Database extends Database
*/
protected $livesInMemory = false;
/**
* @var bool
*/
protected $transactionNesting = 0;
/**
* List of default pragma values
*
@ -465,7 +470,12 @@ class SQLite3Database extends Database
public function transactionStart($transaction_mode = false, $session_characteristics = false)
{
$this->query('BEGIN');
if ($this->transactionNesting > 0) {
$this->transactionSavepoint('NESTEDTRANSACTION' . $this->transactionNesting);
} else {
$this->query('BEGIN');
}
++$this->transactionNesting;
}
public function transactionSavepoint($savepoint)
@ -478,13 +488,22 @@ class SQLite3Database extends Database
if ($savepoint) {
$this->query("ROLLBACK TO $savepoint;");
} else {
$this->query('ROLLBACK;');
--$this->transactionNesting;
if ($this->transactionNesting > 0) {
$this->transactionRollback('NESTEDTRANSACTION' . $this->transactionNesting);
} else {
$this->query('ROLLBACK;');
}
}
}
public function transactionEnd($chain = false)
{
$this->query('COMMIT;');
--$this->transactionNesting;
if ($this->transactionNesting <= 0) {
$this->transactionNesting = 0;
$this->query('COMMIT;');
}
}
public function clearTable($table)