- Fixed transactions in SQLite
This commit is contained in:
parent
d4181065cf
commit
aa07c728fe
|
@ -8,8 +8,8 @@ class SqlPdoObject extends \Ulmus\Common\PdoObject
|
||||||
|
|
||||||
public function beginTransaction(): bool
|
public function beginTransaction(): bool
|
||||||
{
|
{
|
||||||
if ( 0 === ++$this->openedTransaction ) {
|
if ( 0 === $this->openedTransaction++ ) {
|
||||||
return parent::beginTransaction();
|
return $this->openTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
|
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
|
||||||
|
@ -32,4 +32,9 @@ class SqlPdoObject extends \Ulmus\Common\PdoObject
|
||||||
|
|
||||||
return parent::rollback();
|
return parent::rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function openTransaction() : bool
|
||||||
|
{
|
||||||
|
return parent::beginTransaction();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -4,16 +4,23 @@ namespace Ulmus\Common\PdoObject;
|
||||||
|
|
||||||
class SqlitePdoObject extends SqlPdoObject
|
class SqlitePdoObject extends SqlPdoObject
|
||||||
{
|
{
|
||||||
public function beginTransaction(): bool
|
public bool $inTransaction = false;
|
||||||
{
|
|
||||||
if ( 0 === ++$this->openedTransaction ) {
|
|
||||||
return $this->beginImmediateTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
|
public function inTransaction(): bool
|
||||||
|
{
|
||||||
|
return $this->openedTransaction > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function beginImmediateTransaction(): bool
|
public function commit(): bool
|
||||||
|
{
|
||||||
|
if ( 0 === --$this->openedTransaction) {
|
||||||
|
return $this->exec("COMMIT") !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function openTransaction(): bool
|
||||||
{
|
{
|
||||||
return $this->exec("BEGIN IMMEDIATE TRANSACTION") !== false;
|
return $this->exec("BEGIN IMMEDIATE TRANSACTION") !== false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue