- Working on revamping Ulmus bases classes
This commit is contained in:
1 parent
13b7cf06f1
commit
1dcf32e0da
12 files changed
+303
-52
No files matched your search
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Pdo;
|
||||
|
||||
trait SqlitePdoTrait
|
||||
{
|
||||
use SqlPdoTrait;
|
||||
|
||||
public bool $inTransaction = false;
|
||||
|
||||
public function inTransaction(): bool
|
||||
{
|
||||
return $this->openedTransaction > 0;
|
||||
}
|
||||
|
||||
public function commit(): bool
|
||||
{
|
||||
if ( 0 === --$this->openedTransaction) {
|
||||
return $this->exec("COMMIT") !== false;
|
||||
}
|
||||
|
||||
return $this->exec("RELEASE SAVEPOINT transaction_{$this->openedTransaction}") !== false;
|
||||
}
|
||||
|
||||
public function rollback() : bool
|
||||
{
|
||||
if ($this->openedTransaction > 1) {
|
||||
return $this->exec('ROLLBACK TO transaction_' . $this->openedTransaction--) !== false;
|
||||
}
|
||||
elseif ($this->openedTransaction-- === 1) {
|
||||
# We must do it manually since opening a transaction manually stucks PDO into thinking we've got no transaction opened
|
||||
return $this->exec('ROLLBACK') !== false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function openTransaction(): bool
|
||||
{
|
||||
return $this->exec("BEGIN IMMEDIATE TRANSACTION") !== false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user