Skip to content

Commit

Permalink
fix: PDO::errorInfo() can return NULL as a code, but Exception does n…
Browse files Browse the repository at this point in the history
…ot accept NULL code
  • Loading branch information
hubipe authored and dg committed Sep 29, 2023
1 parent e45638e commit 92b8e60
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Dibi/Drivers/PdoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function query(string $sql): ?Dibi\ResultDriver
$this->affectedRows = null;

[$sqlState, $code, $message] = $this->connection->errorInfo();
$code ??= 0;
$message = "SQLSTATE[$sqlState]: $message";
throw match ($this->driverName) {
'mysql' => MySqliDriver::createException($message, $code, $sql),
Expand Down Expand Up @@ -130,7 +131,7 @@ public function begin(?string $savepoint = null): void
{
if (!$this->connection->beginTransaction()) {
$err = $this->connection->errorInfo();
throw new Dibi\DriverException("SQLSTATE[$err[0]]: $err[2]", $err[1]);
throw new Dibi\DriverException("SQLSTATE[$err[0]]: $err[2]", $err[1] ?? 0);
}
}

Expand All @@ -143,7 +144,7 @@ public function commit(?string $savepoint = null): void
{
if (!$this->connection->commit()) {
$err = $this->connection->errorInfo();
throw new Dibi\DriverException("SQLSTATE[$err[0]]: $err[2]", $err[1]);
throw new Dibi\DriverException("SQLSTATE[$err[0]]: $err[2]", $err[1] ?? 0);
}
}

Expand All @@ -156,7 +157,7 @@ public function rollback(?string $savepoint = null): void
{
if (!$this->connection->rollBack()) {
$err = $this->connection->errorInfo();
throw new Dibi\DriverException("SQLSTATE[$err[0]]: $err[2]", $err[1]);
throw new Dibi\DriverException("SQLSTATE[$err[0]]: $err[2]", $err[1] ?? 0);
}
}

Expand Down

0 comments on commit 92b8e60

Please sign in to comment.