mirror of
https://github.com/dg/dibi.git
synced 2025-02-22 09:53:11 +01:00
fix: PDO::errorInfo() can return NULL as a code, but Exception does not accept NULL code
This commit is contained in:
parent
e45638eab4
commit
92b8e6077e
@ -93,6 +93,7 @@ class PdoDriver implements Dibi\Driver
|
|||||||
$this->affectedRows = null;
|
$this->affectedRows = null;
|
||||||
|
|
||||||
[$sqlState, $code, $message] = $this->connection->errorInfo();
|
[$sqlState, $code, $message] = $this->connection->errorInfo();
|
||||||
|
$code ??= 0;
|
||||||
$message = "SQLSTATE[$sqlState]: $message";
|
$message = "SQLSTATE[$sqlState]: $message";
|
||||||
throw match ($this->driverName) {
|
throw match ($this->driverName) {
|
||||||
'mysql' => MySqliDriver::createException($message, $code, $sql),
|
'mysql' => MySqliDriver::createException($message, $code, $sql),
|
||||||
@ -130,7 +131,7 @@ class PdoDriver implements Dibi\Driver
|
|||||||
{
|
{
|
||||||
if (!$this->connection->beginTransaction()) {
|
if (!$this->connection->beginTransaction()) {
|
||||||
$err = $this->connection->errorInfo();
|
$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()) {
|
if (!$this->connection->commit()) {
|
||||||
$err = $this->connection->errorInfo();
|
$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()) {
|
if (!$this->connection->rollBack()) {
|
||||||
$err = $this->connection->errorInfo();
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user