Skip to content

Commit

Permalink
修复
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Mar 24, 2024
1 parent b6ae55e commit 73045da
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 34 deletions.
2 changes: 2 additions & 0 deletions src/Components/pgsql/src/Db/Drivers/PdoPgsql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions src/Components/pgsql/src/Db/Drivers/PdoPgsql/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Statement extends PgsqlBaseStatement implements IPgsqlStatement
{
use TPdoStatement;

public const OFFLINE_CODE_INDEX = 0;

/**
* 更新最后插入ID.
*/
Expand Down
21 changes: 7 additions & 14 deletions src/Db/Drivers/TPdoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ trait TPdoDriver
*/
protected string $statementClass = '';

/**
* 检查是否离线的错误码索引.
*
* @readonly
*/
protected int $checkIsOfflineCodeIndex = 0;

public function __construct(array $option = [])
{
$option['password'] ??= '';
Expand Down Expand Up @@ -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]))

Check warning on line 97 in src/Db/Drivers/TPdoDriver.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Drivers/TPdoDriver.php#L97

Added line #L97 was not covered by tests
{
$this->close();
}
Expand Down Expand Up @@ -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]))

Check warning on line 169 in src/Db/Drivers/TPdoDriver.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Drivers/TPdoDriver.php#L169

Added line #L169 was not covered by tests
{
$this->close();
}
Expand Down Expand Up @@ -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]))

Check warning on line 199 in src/Db/Drivers/TPdoDriver.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Drivers/TPdoDriver.php#L199

Added line #L199 was not covered by tests
{
$this->close();
}
Expand All @@ -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]))

Check warning on line 222 in src/Db/Drivers/TPdoDriver.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Drivers/TPdoDriver.php#L222

Added line #L222 was not covered by tests
{
$this->close();
}
Expand Down Expand Up @@ -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]))

Check warning on line 331 in src/Db/Drivers/TPdoDriver.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Drivers/TPdoDriver.php#L331

Added line #L331 was not covered by tests
{
$this->close();
}
Expand Down Expand Up @@ -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]))

Check warning on line 408 in src/Db/Drivers/TPdoDriver.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Drivers/TPdoDriver.php#L408

Added line #L408 was not covered by tests
{
$this->close();
}
Expand Down Expand Up @@ -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]))

Check warning on line 442 in src/Db/Drivers/TPdoDriver.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Drivers/TPdoDriver.php#L442

Added line #L442 was not covered by tests
{
$this->close();
}
Expand Down
9 changes: 1 addition & 8 deletions src/Db/Drivers/TPdoStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]))

Check warning on line 161 in src/Db/Drivers/TPdoStatement.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Drivers/TPdoStatement.php#L161

Added line #L161 was not covered by tests
{
$this->db->close();
}
Expand Down
7 changes: 1 addition & 6 deletions src/Db/Mysql/Drivers/PdoMysql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand Down
7 changes: 1 addition & 6 deletions src/Db/Mysql/Drivers/PdoMysql/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,5 @@ class Statement extends MysqlBaseStatement implements IMysqlStatement
{
use TPdoStatement;

/**
* 检查是否离线的错误码索引.
*
* @readonly
*/
protected int $checkIsOfflineCodeIndex = 1;
public const OFFLINE_CODE_INDEX = 1;
}

0 comments on commit 73045da

Please sign in to comment.