Better transaction handling
This commit is contained in:
parent
11e6e43072
commit
4018095088
1 changed files with 21 additions and 3 deletions
|
@ -12,6 +12,9 @@ abstract class AbstractSQLDriver extends AbstractDriver
|
|||
public $lastPreparationErrorOn;
|
||||
public $pdo;
|
||||
protected $schemas = [];
|
||||
protected $transactions = 0;
|
||||
|
||||
const NESTED_TRANSACTION_SUPPORT = false;
|
||||
|
||||
abstract protected function sql_ddl(array $args = []): string;
|
||||
abstract protected function expandPath(string $path): string;
|
||||
|
@ -68,17 +71,32 @@ abstract class AbstractSQLDriver extends AbstractDriver
|
|||
|
||||
public function beginTransaction(): bool
|
||||
{
|
||||
$this->transactions++;
|
||||
if (static::NESTED_TRANSACTION_SUPPORT || !$this->pdo->inTransaction()) {
|
||||
return $this->pdo->beginTransaction();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function commit(): bool
|
||||
{
|
||||
$this->transactions--;
|
||||
if (static::NESTED_TRANSACTION_SUPPORT || ($this->transactions == 0 && $this->pdo->inTransaction())) {
|
||||
return $this->pdo->commit();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function rollBack(): bool
|
||||
{
|
||||
$this->transactions--;
|
||||
if (static::NESTED_TRANSACTION_SUPPORT || ($this->transactions == 0 && $this->pdo->inTransaction())) {
|
||||
return $this->pdo->rollBack();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function expandPaths($value)
|
||||
|
|
Loading…
Reference in a new issue