From f176bb0a39676d47d347b1b5b81a6a0753fb66f1 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Fri, 9 Feb 2018 11:24:35 +0000 Subject: [PATCH] FIX Add nested transaction support --- code/SQLite3Database.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/code/SQLite3Database.php b/code/SQLite3Database.php index 44f83a0..dbb64b1 100644 --- a/code/SQLite3Database.php +++ b/code/SQLite3Database.php @@ -50,6 +50,11 @@ class SQLite3Database extends Database */ protected $livesInMemory = false; + /** + * @var bool + */ + protected $transactionNesting = 0; + /** * List of default pragma values * @@ -448,7 +453,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) @@ -461,13 +471,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)