- Fixed transactions in SQLite

This commit is contained in:
Dave M. 2024-06-28 07:47:53 -04:00
parent d4181065cf
commit aa07c728fe
2 changed files with 21 additions and 9 deletions

View File

@ -8,8 +8,8 @@ class SqlPdoObject extends \Ulmus\Common\PdoObject
public function beginTransaction(): bool
{
if ( 0 === ++$this->openedTransaction ) {
return parent::beginTransaction();
if ( 0 === $this->openedTransaction++ ) {
return $this->openTransaction();
}
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
@ -32,4 +32,9 @@ class SqlPdoObject extends \Ulmus\Common\PdoObject
return parent::rollback();
}
protected function openTransaction() : bool
{
return parent::beginTransaction();
}
}

View File

@ -4,16 +4,23 @@ namespace Ulmus\Common\PdoObject;
class SqlitePdoObject extends SqlPdoObject
{
public function beginTransaction(): bool
public bool $inTransaction = false;
public function inTransaction(): bool
{
if ( 0 === ++$this->openedTransaction ) {
return $this->beginImmediateTransaction();
return $this->openedTransaction > 0;
}
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
public function commit(): bool
{
if ( 0 === --$this->openedTransaction) {
return $this->exec("COMMIT") !== false;
}
protected function beginImmediateTransaction(): bool
return false;
}
protected function openTransaction(): bool
{
return $this->exec("BEGIN IMMEDIATE TRANSACTION") !== false;
}