1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-21 09:23:57 +01:00

fix: PDO::errorInfo() can return NULL as a code, but Exception does not accept NULL code

This commit is contained in:
Petr Hubík 2023-09-21 10:01:54 +02:00 committed by David Grudl
parent e45638eab4
commit 92b8e6077e

View File

@ -93,6 +93,7 @@ class PdoDriver implements Dibi\Driver
$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),
@ -130,7 +131,7 @@ class PdoDriver implements Dibi\Driver
{
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);
}
}
@ -143,7 +144,7 @@ class PdoDriver implements Dibi\Driver
{
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);
}
}
@ -156,7 +157,7 @@ class PdoDriver implements Dibi\Driver
{
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);
}
}