mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
FIX Add nested transaction support
This commit is contained in:
parent
e8f4e55b8a
commit
f176bb0a39
@ -50,6 +50,11 @@ class SQLite3Database extends Database
|
|||||||
*/
|
*/
|
||||||
protected $livesInMemory = false;
|
protected $livesInMemory = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $transactionNesting = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of default pragma values
|
* List of default pragma values
|
||||||
*
|
*
|
||||||
@ -448,8 +453,13 @@ class SQLite3Database extends Database
|
|||||||
|
|
||||||
public function transactionStart($transaction_mode = false, $session_characteristics = false)
|
public function transactionStart($transaction_mode = false, $session_characteristics = false)
|
||||||
{
|
{
|
||||||
|
if ($this->transactionNesting > 0) {
|
||||||
|
$this->transactionSavepoint('NESTEDTRANSACTION' . $this->transactionNesting);
|
||||||
|
} else {
|
||||||
$this->query('BEGIN');
|
$this->query('BEGIN');
|
||||||
}
|
}
|
||||||
|
++$this->transactionNesting;
|
||||||
|
}
|
||||||
|
|
||||||
public function transactionSavepoint($savepoint)
|
public function transactionSavepoint($savepoint)
|
||||||
{
|
{
|
||||||
@ -460,15 +470,24 @@ class SQLite3Database extends Database
|
|||||||
{
|
{
|
||||||
if ($savepoint) {
|
if ($savepoint) {
|
||||||
$this->query("ROLLBACK TO $savepoint;");
|
$this->query("ROLLBACK TO $savepoint;");
|
||||||
|
} else {
|
||||||
|
--$this->transactionNesting;
|
||||||
|
if ($this->transactionNesting > 0) {
|
||||||
|
$this->transactionRollback('NESTEDTRANSACTION' . $this->transactionNesting);
|
||||||
} else {
|
} else {
|
||||||
$this->query('ROLLBACK;');
|
$this->query('ROLLBACK;');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function transactionEnd($chain = false)
|
public function transactionEnd($chain = false)
|
||||||
{
|
{
|
||||||
|
--$this->transactionNesting;
|
||||||
|
if ($this->transactionNesting <= 0) {
|
||||||
|
$this->transactionNesting = 0;
|
||||||
$this->query('COMMIT;');
|
$this->query('COMMIT;');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function clearTable($table)
|
public function clearTable($table)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user