aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2025-03-04 16:32:55 +0100
committerGitHub <noreply@github.com>2025-03-04 16:32:55 +0100
commit9bbe8c59d75de415a81e3fcfc6b6445689df3e83 (patch)
tree2bff46a478a5cfdf6239fa53617fb428f54a96f5 /lib
parent32bfb0929f0b1557a1b6c5ac90889cb561678b3d (diff)
parentf3bd4a79d9e70882c0b78664d94b726c1b6a4ec8 (diff)
downloadnextcloud-server-9bbe8c59d75de415a81e3fcfc6b6445689df3e83.tar.gz
nextcloud-server-9bbe8c59d75de415a81e3fcfc6b6445689df3e83.zip
Merge pull request #51073 from nextcloud/dbal-exception-query
feat: log query for dbal exceptions
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DB/ConnectionAdapter.php6
-rw-r--r--lib/private/DB/Exceptions/DbalException.php9
2 files changed, 9 insertions, 6 deletions
diff --git a/lib/private/DB/ConnectionAdapter.php b/lib/private/DB/ConnectionAdapter.php
index ba3bf90c2e8..78ca780f218 100644
--- a/lib/private/DB/ConnectionAdapter.php
+++ b/lib/private/DB/ConnectionAdapter.php
@@ -50,7 +50,7 @@ class ConnectionAdapter implements IDBConnection {
$this->inner->executeQuery($sql, $params, $types)
);
} catch (Exception $e) {
- throw DbalException::wrap($e);
+ throw DbalException::wrap($e, '', $sql);
}
}
@@ -58,7 +58,7 @@ class ConnectionAdapter implements IDBConnection {
try {
return $this->inner->executeUpdate($sql, $params, $types);
} catch (Exception $e) {
- throw DbalException::wrap($e);
+ throw DbalException::wrap($e, '', $sql);
}
}
@@ -66,7 +66,7 @@ class ConnectionAdapter implements IDBConnection {
try {
return $this->inner->executeStatement($sql, $params, $types);
} catch (Exception $e) {
- throw DbalException::wrap($e);
+ throw DbalException::wrap($e, '', $sql);
}
}
diff --git a/lib/private/DB/Exceptions/DbalException.php b/lib/private/DB/Exceptions/DbalException.php
index 05ea9e22a5d..2ce6ddf80a6 100644
--- a/lib/private/DB/Exceptions/DbalException.php
+++ b/lib/private/DB/Exceptions/DbalException.php
@@ -35,26 +35,29 @@ use OCP\DB\Exception;
class DbalException extends Exception {
/** @var \Doctrine\DBAL\Exception */
private $original;
+ public readonly ?string $query;
/**
* @param \Doctrine\DBAL\Exception $original
* @param int $code
* @param string $message
*/
- private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message) {
+ private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message, ?string $query = null) {
parent::__construct(
$message,
$code,
$original
);
$this->original = $original;
+ $this->query = $query;
}
- public static function wrap(\Doctrine\DBAL\Exception $original, string $message = ''): self {
+ public static function wrap(\Doctrine\DBAL\Exception $original, string $message = '', ?string $query = null): self {
return new self(
$original,
is_int($original->getCode()) ? $original->getCode() : 0,
- empty($message) ? $original->getMessage() : $message
+ empty($message) ? $original->getMessage() : $message,
+ $query,
);
}