From 73045da7fc45d11e9dfc5eaebac9bdb2084013e0 Mon Sep 17 00:00:00 2001 From: Yurun Date: Sun, 24 Mar 2024 14:55:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pgsql/src/Db/Drivers/PdoPgsql/Driver.php | 2 ++ .../src/Db/Drivers/PdoPgsql/Statement.php | 2 ++ src/Db/Drivers/TPdoDriver.php | 21 +++++++------------ src/Db/Drivers/TPdoStatement.php | 9 +------- src/Db/Mysql/Drivers/PdoMysql/Driver.php | 7 +------ src/Db/Mysql/Drivers/PdoMysql/Statement.php | 7 +------ 6 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/Components/pgsql/src/Db/Drivers/PdoPgsql/Driver.php b/src/Components/pgsql/src/Db/Drivers/PdoPgsql/Driver.php index 8b57195a6d..f7062efd84 100644 --- a/src/Components/pgsql/src/Db/Drivers/PdoPgsql/Driver.php +++ b/src/Components/pgsql/src/Db/Drivers/PdoPgsql/Driver.php @@ -20,6 +20,8 @@ class Driver extends PgsqlBase __construct as private tPdoDriverConstruct; } + public const OFFLINE_CODE_INDEX = 0; + public function __construct(array $option = []) { $option['username'] ??= 'postgres'; diff --git a/src/Components/pgsql/src/Db/Drivers/PdoPgsql/Statement.php b/src/Components/pgsql/src/Db/Drivers/PdoPgsql/Statement.php index ef3f2e3d9f..2b0f734239 100644 --- a/src/Components/pgsql/src/Db/Drivers/PdoPgsql/Statement.php +++ b/src/Components/pgsql/src/Db/Drivers/PdoPgsql/Statement.php @@ -18,6 +18,8 @@ class Statement extends PgsqlBaseStatement implements IPgsqlStatement { use TPdoStatement; + public const OFFLINE_CODE_INDEX = 0; + /** * 更新最后插入ID. */ diff --git a/src/Db/Drivers/TPdoDriver.php b/src/Db/Drivers/TPdoDriver.php index feedb6a1c0..c50dbd48c0 100644 --- a/src/Db/Drivers/TPdoDriver.php +++ b/src/Db/Drivers/TPdoDriver.php @@ -45,13 +45,6 @@ trait TPdoDriver */ protected string $statementClass = ''; - /** - * 检查是否离线的错误码索引. - * - * @readonly - */ - protected int $checkIsOfflineCodeIndex = 0; - public function __construct(array $option = []) { $option['password'] ??= ''; @@ -101,7 +94,7 @@ public function ping(): bool } catch (\PDOException $e) { - if (isset($e->errorInfo[$this->checkIsOfflineCodeIndex]) && $this->checkCodeIsOffline($e->errorInfo[$this->checkIsOfflineCodeIndex])) + if (isset($e->errorInfo[self::OFFLINE_CODE_INDEX]) && $this->checkCodeIsOffline($e->errorInfo[self::OFFLINE_CODE_INDEX])) { $this->close(); } @@ -173,7 +166,7 @@ public function beginTransaction(): bool } catch (\PDOException $e) { - if (isset($e->errorInfo[$this->checkIsOfflineCodeIndex]) && $this->checkCodeIsOffline($e->errorInfo[$this->checkIsOfflineCodeIndex])) + if (isset($e->errorInfo[self::OFFLINE_CODE_INDEX]) && $this->checkCodeIsOffline($e->errorInfo[self::OFFLINE_CODE_INDEX])) { $this->close(); } @@ -203,7 +196,7 @@ public function commit(): bool } catch (\PDOException $e) { - if (isset($e->errorInfo[$this->checkIsOfflineCodeIndex]) && $this->checkCodeIsOffline($e->errorInfo[$this->checkIsOfflineCodeIndex])) + if (isset($e->errorInfo[self::OFFLINE_CODE_INDEX]) && $this->checkCodeIsOffline($e->errorInfo[self::OFFLINE_CODE_INDEX])) { $this->close(); } @@ -226,7 +219,7 @@ public function rollBack(?int $levels = null): bool } catch (\PDOException $e) { - if (isset($e->errorInfo[$this->checkIsOfflineCodeIndex]) && $this->checkCodeIsOffline($e->errorInfo[$this->checkIsOfflineCodeIndex])) + if (isset($e->errorInfo[self::OFFLINE_CODE_INDEX]) && $this->checkCodeIsOffline($e->errorInfo[self::OFFLINE_CODE_INDEX])) { $this->close(); } @@ -335,7 +328,7 @@ public function exec(string $sql): int } catch (\PDOException $e) { - if (isset($e->errorInfo[$this->checkIsOfflineCodeIndex]) && $this->checkCodeIsOffline($e->errorInfo[$this->checkIsOfflineCodeIndex])) + if (isset($e->errorInfo[self::OFFLINE_CODE_INDEX]) && $this->checkCodeIsOffline($e->errorInfo[self::OFFLINE_CODE_INDEX])) { $this->close(); } @@ -412,7 +405,7 @@ public function prepare(string $sql, array $driverOptions = []): IStatement } catch (\PDOException $e) { - if (isset($e->errorInfo[$this->checkIsOfflineCodeIndex]) && $this->checkCodeIsOffline($e->errorInfo[$this->checkIsOfflineCodeIndex])) + if (isset($e->errorInfo[self::OFFLINE_CODE_INDEX]) && $this->checkCodeIsOffline($e->errorInfo[self::OFFLINE_CODE_INDEX])) { $this->close(); } @@ -446,7 +439,7 @@ public function query(string $sql): IStatement } catch (\PDOException $e) { - if (isset($e->errorInfo[$this->checkIsOfflineCodeIndex]) && $this->checkCodeIsOffline($e->errorInfo[$this->checkIsOfflineCodeIndex])) + if (isset($e->errorInfo[self::OFFLINE_CODE_INDEX]) && $this->checkCodeIsOffline($e->errorInfo[self::OFFLINE_CODE_INDEX])) { $this->close(); } diff --git a/src/Db/Drivers/TPdoStatement.php b/src/Db/Drivers/TPdoStatement.php index 62067dd4bc..c63ecdd753 100644 --- a/src/Db/Drivers/TPdoStatement.php +++ b/src/Db/Drivers/TPdoStatement.php @@ -32,13 +32,6 @@ trait TPdoStatement */ protected $lastInsertId = ''; - /** - * 检查是否离线的错误码索引. - * - * @readonly - */ - protected int $checkIsOfflineCodeIndex = 0; - public function __construct(IDb $db, \PDOStatement $statement, bool $isExecuted = false) { $this->db = $db; @@ -165,7 +158,7 @@ public function execute(array $inputParameters = null): bool } catch (\PDOException $e) { - if (isset($e->errorInfo[$this->checkIsOfflineCodeIndex]) && $this->db->checkCodeIsOffline($e->errorInfo[$this->checkIsOfflineCodeIndex])) + if (isset($e->errorInfo[self::OFFLINE_CODE_INDEX]) && $this->db->checkCodeIsOffline($e->errorInfo[self::OFFLINE_CODE_INDEX])) { $this->db->close(); } diff --git a/src/Db/Mysql/Drivers/PdoMysql/Driver.php b/src/Db/Mysql/Drivers/PdoMysql/Driver.php index 13695090fb..d79a4554b3 100644 --- a/src/Db/Mysql/Drivers/PdoMysql/Driver.php +++ b/src/Db/Mysql/Drivers/PdoMysql/Driver.php @@ -20,12 +20,7 @@ class Driver extends MysqlBase __construct as private tPdoDriverConstruct; } - /** - * 检查是否离线的错误码索引. - * - * @readonly - */ - protected int $checkIsOfflineCodeIndex = 1; + public const OFFLINE_CODE_INDEX = 1; public function __construct(array $option = []) { diff --git a/src/Db/Mysql/Drivers/PdoMysql/Statement.php b/src/Db/Mysql/Drivers/PdoMysql/Statement.php index 33c205473a..b872c4d5e4 100644 --- a/src/Db/Mysql/Drivers/PdoMysql/Statement.php +++ b/src/Db/Mysql/Drivers/PdoMysql/Statement.php @@ -17,10 +17,5 @@ class Statement extends MysqlBaseStatement implements IMysqlStatement { use TPdoStatement; - /** - * 检查是否离线的错误码索引. - * - * @readonly - */ - protected int $checkIsOfflineCodeIndex = 1; + public const OFFLINE_CODE_INDEX = 1; }