From 6b7e73a0ee38f3b4701c99b754da55f4514f7f31 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 31 Jul 2020 10:50:32 +0200 Subject: [PATCH] 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. --- .../DatabaseQueryExecutionException.class.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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; } /** -- 2.20.1