Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: log query for dbal exceptions
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Feb 26, 2025
commit f3bd4a79d9e70882c0b78664d94b726c1b6a4ec8
6 changes: 3 additions & 3 deletions lib/private/DB/ConnectionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ public function executeQuery(string $sql, array $params = [], $types = []): IRes
$this->inner->executeQuery($sql, $params, $types)
);
} catch (Exception $e) {
throw DbalException::wrap($e);
throw DbalException::wrap($e, '', $sql);
}
}

public function executeUpdate(string $sql, array $params = [], array $types = []): int {
try {
return $this->inner->executeUpdate($sql, $params, $types);
} catch (Exception $e) {
throw DbalException::wrap($e);
throw DbalException::wrap($e, '', $sql);
}
}

public function executeStatement($sql, array $params = [], array $types = []): int {
try {
return $this->inner->executeStatement($sql, $params, $types);
} catch (Exception $e) {
throw DbalException::wrap($e);
throw DbalException::wrap($e, '', $sql);
}
}

Expand Down
9 changes: 6 additions & 3 deletions lib/private/DB/Exceptions/DbalException.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,29 @@
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,
);
}

Expand Down
Loading