Skip to content

Commit 5a32ddc

Browse files
icewind1991AndyScherzinger
authored andcommitted
feat: log query for dbal exceptions
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 126843a commit 5a32ddc

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/private/DB/ConnectionAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,23 @@ public function executeQuery(string $sql, array $params = [], $types = []): IRes
6969
$this->inner->executeQuery($sql, $params, $types)
7070
);
7171
} catch (Exception $e) {
72-
throw DbalException::wrap($e);
72+
throw DbalException::wrap($e, '', $sql);
7373
}
7474
}
7575

7676
public function executeUpdate(string $sql, array $params = [], array $types = []): int {
7777
try {
7878
return $this->inner->executeUpdate($sql, $params, $types);
7979
} catch (Exception $e) {
80-
throw DbalException::wrap($e);
80+
throw DbalException::wrap($e, '', $sql);
8181
}
8282
}
8383

8484
public function executeStatement($sql, array $params = [], array $types = []): int {
8585
try {
8686
return $this->inner->executeStatement($sql, $params, $types);
8787
} catch (Exception $e) {
88-
throw DbalException::wrap($e);
88+
throw DbalException::wrap($e, '', $sql);
8989
}
9090
}
9191

lib/private/DB/Exceptions/DbalException.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,29 @@
5252
class DbalException extends Exception {
5353
/** @var \Doctrine\DBAL\Exception */
5454
private $original;
55+
public ?string $query;
5556

5657
/**
5758
* @param \Doctrine\DBAL\Exception $original
5859
* @param int $code
5960
* @param string $message
6061
*/
61-
private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message) {
62+
private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message, ?string $query = null) {
6263
parent::__construct(
6364
$message,
6465
$code,
6566
$original
6667
);
6768
$this->original = $original;
69+
$this->query = $query;
6870
}
6971

70-
public static function wrap(\Doctrine\DBAL\Exception $original, string $message = ''): self {
72+
public static function wrap(\Doctrine\DBAL\Exception $original, string $message = '', ?string $query = null): self {
7173
return new self(
7274
$original,
7375
is_int($original->getCode()) ? $original->getCode() : 0,
74-
empty($message) ? $original->getMessage() : $message
76+
empty($message) ? $original->getMessage() : $message,
77+
$query,
7578
);
7679
}
7780

0 commit comments

Comments
 (0)