From 84d1701ff7c41c62290ff8d8f85cb1ccdf9eedc7 Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Thu, 6 Apr 2023 22:55:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Command.php | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/Command.php b/Command.php index 86e0186..4545742 100644 --- a/Command.php +++ b/Command.php @@ -28,19 +28,19 @@ class Command extends Component const FETCH_ALL = 'fetchAll'; const EXECUTE = 'execute'; const FETCH_COLUMN = 'fetchColumn'; - + const DB_ERROR_MESSAGE = 'The system is busy, please try again later.'; - + /** @var Connection */ public Connection $connection; - + /** @var ?string */ public ?string $sql = ''; - + /** @var array */ public array $params = []; - - + + /** * @return int|bool * @throws Exception @@ -49,7 +49,7 @@ class Command extends Component { return $this->_execute(); } - + /** * @return int|bool * @throws Exception @@ -58,8 +58,8 @@ class Command extends Component { return $this->_execute(); } - - + + /** * @return bool|array|null * @throws Exception @@ -82,7 +82,7 @@ class Command extends Component $this->connection->release($pdo ?? null); } } - + /** * @return bool|array|null * @throws Exception @@ -105,7 +105,7 @@ class Command extends Component $this->connection->release($client ?? null); } } - + /** * @return bool|array|null * @throws Exception @@ -128,7 +128,7 @@ class Command extends Component $this->connection->release($client ?? null); } } - + /** * @return int|bool * @throws Exception @@ -151,8 +151,8 @@ class Command extends Component $this->connection->release($client ?? null); } } - - + + /** * @return int|bool * @throws Exception @@ -161,7 +161,7 @@ class Command extends Component { return $this->_execute(); } - + /** * @return bool|int * @throws ConfigException @@ -179,6 +179,10 @@ class Command extends Component } $result = $client->lastInsertId(); $prepare->closeCursor(); + + if (!$client->inTransaction()) { + $this->connection->release($client); + } return $result == 0 ? true : $result; } catch (\Throwable $throwable) { if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) { @@ -187,8 +191,8 @@ class Command extends Component return $this->error($throwable); } } - - + + /** * @param \Throwable $throwable * @return bool @@ -198,8 +202,8 @@ class Command extends Component $message = $this->sql . '(' . json_encode($this->params, JSON_UNESCAPED_UNICODE) . ');'; return $this->logger->addError($message . $throwable->getMessage(), 'mysql'); } - - + + /** * @return int|bool * @throws Exception @@ -208,7 +212,7 @@ class Command extends Component { return $this->_execute(); } - + /** * @return int|bool * @throws Exception @@ -217,7 +221,7 @@ class Command extends Component { return $this->_execute(); } - + /** * @param array $data * @return $this @@ -229,7 +233,7 @@ class Command extends Component } return $this; } - + /** * @param $sql * @return $this @@ -240,5 +244,5 @@ class Command extends Component $this->sql = $sql; return $this; } - + }