- Began WIP on SQL specific PdoObject
This commit is contained in:
1 parent
1d38ae8245
commit
e37944c63a
3 files changed
+57
-1
No files matched your search
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Common\PdoObject;
|
||||
|
||||
class SqlPdoObject extends \Ulmus\Common\PdoObject
|
||||
{
|
||||
protected int $openedTransaction = 0;
|
||||
|
||||
public function beginTransaction(): bool
|
||||
{
|
||||
if ( 0 === ++$this->openedTransaction ) {
|
||||
return parent::beginTransaction();
|
||||
}
|
||||
|
||||
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
|
||||
}
|
||||
|
||||
public function commit() : bool
|
||||
{
|
||||
if ( 0 === --$this->openedTransaction) {
|
||||
return parent::commit();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function rollback() : bool
|
||||
{
|
||||
if (0 !== $this->openedTransaction) {
|
||||
return $this->exec('ROLLBACK TO transaction_' . $this->openedTransaction--) !== false;
|
||||
}
|
||||
|
||||
return parent::rollback();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Common\PdoObject;
|
||||
|
||||
class SqlitePdoObject extends SqlPdoObject
|
||||
{
|
||||
public function beginTransaction(): bool
|
||||
{
|
||||
if ( 0 === ++$this->openedTransaction ) {
|
||||
return $this->beginImmediateTransaction();
|
||||
}
|
||||
|
||||
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
|
||||
}
|
||||
|
||||
protected function beginImmediateTransaction(): bool
|
||||
{
|
||||
return $this->exec("BEGIN IMMEDIATE TRANSACTION") !== false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user