Merge pull request #51230 from nextcloud/backport/51073/stable31

[stable31] feat: log query for dbal exceptions
This commit is contained in:
Kate 2025-03-04 17:05:45 +01:00 committed by GitHub
commit aed2cc2298
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View file

@ -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);
}
}

View file

@ -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,
);
}