This commit is contained in:
2022-09-20 18:15:50 +08:00
parent 4dc55fd772
commit 58c3b38c73
+14 -11
View File
@@ -18,6 +18,7 @@ use Database\Mysql\PDO;
use Database\Mysql\Schema; use Database\Mysql\Schema;
use Exception; use Exception;
use Kiri; use Kiri;
use Kiri\Context;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Events\EventProvider; use Kiri\Events\EventProvider;
@@ -191,10 +192,10 @@ class Connection extends Component
*/ */
public function getPdo(): PDO public function getPdo(): PDO
{ {
if (!$this->_pdo) { if (!Context::hasContext('master:client')) {
$this->_pdo = $this->getMasterClient(); Context::setContext('master:client', $this->getMasterClient());
} }
return $this->_pdo; return Context::getContext('master:client');
} }
/** /**
@@ -212,11 +213,12 @@ class Connection extends Component
*/ */
public function rollback() public function rollback()
{ {
if ($this->_pdo->inTransaction()) { $pdo = $this->getPdo();
$this->_pdo->rollback(); if ($pdo->inTransaction()) {
$pdo->rollback();
} }
$this->release($this->_pdo, true); $this->release($pdo, true);
$this->_pdo = null; Context::remove('master:client');
} }
/** /**
@@ -225,11 +227,12 @@ class Connection extends Component
*/ */
public function commit() public function commit()
{ {
if ($this->_pdo->inTransaction()) { $pdo = $this->getPdo();
$this->_pdo->commit(); if ($pdo->inTransaction()) {
$pdo->commit();
} }
$this->release($this->_pdo, true); $this->release($pdo, true);
$this->_pdo = null; Context::remove('master:client');
} }