Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] feat: log query for dbal exceptions #51232

Open
wants to merge 1 commit into
base: stable29
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions lib/private/DB/ConnectionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,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 @@ -52,26 +52,29 @@
class DbalException extends Exception {
/** @var \Doctrine\DBAL\Exception */
private $original;
public ?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