This commit is contained in:
2023-11-23 15:27:57 +08:00
parent f8a1e700a7
commit d42e30ecbe
+5 -20
View File
@@ -215,11 +215,7 @@ class Connection extends Component
public function beginTransaction(): static public function beginTransaction(): static
{ {
if ($this->storey == 0) { if ($this->storey == 0) {
/** @var PDO $pdo */ $pdo = $this->getTransactionClient();
$pdo = Context::get($this->cds);
if ($pdo == null) {
$pdo = $this->getTransactionClient();
}
if (!$pdo->inTransaction()) { if (!$pdo->inTransaction()) {
$pdo->beginTransaction(); $pdo->beginTransaction();
} }
@@ -261,14 +257,8 @@ class Connection extends Component
{ {
$this->storey--; $this->storey--;
if ($this->storey == 0) { if ($this->storey == 0) {
/** @var PDO $pdo */ $pdo = $this->getTransactionClient();
$pdo = Context::get($this->cds); $pdo->rollback();
if ($pdo === null) {
throw new Exception(self::ERROR_MSG);
}
if ($this->inTransaction()) {
$pdo->rollback();
}
$this->release($pdo); $this->release($pdo);
} }
} }
@@ -281,13 +271,8 @@ class Connection extends Component
{ {
$this->storey--; $this->storey--;
if ($this->storey == 0) { if ($this->storey == 0) {
$pdo = Context::get($this->cds); $pdo = $this->getTransactionClient();
if ($pdo === null) { $pdo->commit();
throw new Exception(self::ERROR_MSG);
}
if ($this->inTransaction()) {
$pdo->commit();
}
$this->release($pdo); $this->release($pdo);
} }
} }