- Sqlite now handles concurrency with transactions

This commit is contained in:
Dave Mc Nicoll committed 2025-02-25 14:09:41 +00:00
1 parent 0fd6889c6f
commit e0ec140661
6 files changed
+26 -10

No files matched your search

+2 -4
View File
@@ -56,7 +56,7 @@ class PdoObject extends PDO {
}
}
catch (\Throwable $e) {
throw new \PdoException($e->getMessage() . " `$sql` with data:" . json_encode($parameters));
throw new \PdoException($e->getMessage() . " `$sql` with data:" . json_encode($parameters), (int) $e->getCode(), $e);
}
return null;
@@ -83,7 +83,7 @@ class PdoObject extends PDO {
$this->lastInsertId = null;
try {
if ( ! $this->inTransaction() ) {
if (! $this->inTransaction()) {
$this->beginTransaction();
}
@@ -113,8 +113,6 @@ class PdoObject extends PDO {
catch (\Throwable $e) {
throw $e;
}
return null;
}
protected function bindVariables(PDOStatement $statement, array &$parameters) : void
+7 -4
View File
@@ -12,7 +12,7 @@ class SqlPdoObject extends \Ulmus\Common\PdoObject
return $this->openTransaction();
}
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
return $this->exec("SAVEPOINT transaction_{$this->openedTransaction}") !== false;
}
public function commit() : bool
@@ -21,16 +21,19 @@ class SqlPdoObject extends \Ulmus\Common\PdoObject
return parent::commit();
}
return false;
return $this->exec("RELEASE SAVEPOINT transaction_{$this->openedTransaction}") !== false;
}
public function rollback() : bool
{
if (0 !== $this->openedTransaction) {
if ($this->openedTransaction > 1) {
return $this->exec('ROLLBACK TO transaction_' . $this->openedTransaction--) !== false;
}
elseif ($this->openedTransaction-- === 1) {
return parent::rollback();
}
return parent::rollback();
return false;
}
protected function openTransaction() : bool
+13
View File
@@ -17,6 +17,19 @@ class SqlitePdoObject extends SqlPdoObject
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;
}