qqq
This commit is contained in:
+2
-4
@@ -177,7 +177,7 @@ class Command extends Component
|
|||||||
private function _execute(): bool|int
|
private function _execute(): bool|int
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$client = $this->connection->getTransactionClient();
|
$client = $this->connection->getConnection();
|
||||||
if (($prepare = $client->prepare($this->sql)) === false) {
|
if (($prepare = $client->prepare($this->sql)) === false) {
|
||||||
throw new Exception($client->errorInfo()[1]);
|
throw new Exception($client->errorInfo()[1]);
|
||||||
}
|
}
|
||||||
@@ -194,9 +194,7 @@ class Command extends Component
|
|||||||
}
|
}
|
||||||
return $this->error($throwable);
|
return $this->error($throwable);
|
||||||
} finally {
|
} finally {
|
||||||
if (isset($client) && !$client->inTransaction()) {
|
$this->connection->release($client ?? null);
|
||||||
$this->connection->release($client);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-4
@@ -123,7 +123,11 @@ class Connection extends Component
|
|||||||
*/
|
*/
|
||||||
public function getConnection(): PDO
|
public function getConnection(): PDO
|
||||||
{
|
{
|
||||||
return $this->pool()->get($this->cds);
|
if (!$this->inTransaction()) {
|
||||||
|
return $this->pool()->get($this->cds);
|
||||||
|
} else {
|
||||||
|
return $this->getTransactionClient();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -136,7 +140,7 @@ class Connection extends Component
|
|||||||
if ($this->storey == 0) {
|
if ($this->storey == 0) {
|
||||||
/** @var PDO $pdo */
|
/** @var PDO $pdo */
|
||||||
$pdo = Context::get($this->cds);
|
$pdo = Context::get($this->cds);
|
||||||
if ($pdo !== null && !$pdo->inTransaction()) {
|
if ($pdo instanceof PDO && !$pdo->inTransaction()) {
|
||||||
$pdo->beginTransaction();
|
$pdo->beginTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,12 +230,14 @@ class Connection extends Component
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* 回收链接
|
* 回收链接
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function release(?PDO $PDO): void
|
public function release(?PDO $PDO): void
|
||||||
{
|
{
|
||||||
|
if ($PDO === null || $PDO->inTransaction()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->pool()->push($this->cds, $PDO);
|
$this->pool()->push($this->cds, $PDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +249,7 @@ class Connection extends Component
|
|||||||
*/
|
*/
|
||||||
public function clear_connection(): void
|
public function clear_connection(): void
|
||||||
{
|
{
|
||||||
$this->pool()->clean($this->cds);
|
$this->pool()->flush($this->cds, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user