mirror of
https://github.com/nextcloud/server.git
synced 2026-05-26 19:32:28 -04:00
Merge pull request #51230 from nextcloud/backport/51073/stable31
[stable31] feat: log query for dbal exceptions
This commit is contained in:
commit
aed2cc2298
2 changed files with 9 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue