From: Tim Düsterhus Date: Fri, 31 Jul 2020 08:50:32 +0000 (+0200) Subject: Allow retrieving the driver specific error code from DatabaseQueryExecutionException X-Git-Tag: 5.3.0_Alpha_1~110^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6b7e73a0ee38f3b4701c99b754da55f4514f7f31;p=GitHub%2FWoltLab%2FWCF.git Allow retrieving the driver specific error code from DatabaseQueryExecutionException A single ANSI SQLSTATE can indicate several distinct error conditions. The driver code appears to be unique for MySQL. --- diff --git a/wcfsetup/install/files/lib/system/database/exception/DatabaseQueryExecutionException.class.php b/wcfsetup/install/files/lib/system/database/exception/DatabaseQueryExecutionException.class.php index c04043f836..16bf66151f 100644 --- a/wcfsetup/install/files/lib/system/database/exception/DatabaseQueryExecutionException.class.php +++ b/wcfsetup/install/files/lib/system/database/exception/DatabaseQueryExecutionException.class.php @@ -19,6 +19,18 @@ class DatabaseQueryExecutionException extends DatabaseQueryException implements */ protected $parameters = []; + /** + * @var string|null + * @since 5.3 + */ + protected $sqlState; + + /** + * @var string|null + * @since 5.3 + */ + protected $driverCode; + /** @noinspection PhpMissingParentConstructorInspection */ /** * @inheritDoc @@ -27,6 +39,31 @@ class DatabaseQueryExecutionException extends DatabaseQueryException implements parent::__construct($message, $previous); $this->parameters = $parameters; + if ($previous) { + $errorInfo = $previous->errorInfo; + $this->sqlState = $errorInfo[0] ?? null; + $this->driverCode = $errorInfo[1] ?? null; + } + } + + /** + * Returns the ANSI SQLSTATE or null. + * + * @return string|null + * @since 5.3 + */ + public function getSqlState() { + return $this->sqlState; + } + + /** + * Returns the driver specific error code or null. + * + * @return string|null + * @since 5.3 + */ + public function getDriverCode() { + return $this->driverCode; } /**