42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?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;
|
|
}
|
|
} |