Skip to content

Commit aed2cc2

Browse files
Merge pull request #51230 from nextcloud/backport/51073/stable31
[stable31] feat: log query for dbal exceptions
2 parents 72ee217 + 0ae944d commit aed2cc2

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
@@ -50,23 +50,23 @@ public function executeQuery(string $sql, array $params = [], $types = []): IRes
5050
$this->inner->executeQuery($sql, $params, $types)
5151
);
5252
} catch (Exception $e) {
53-
throw DbalException::wrap($e);
53+
throw DbalException::wrap($e, '', $sql);
5454
}
5555
}
5656

5757
public function executeUpdate(string $sql, array $params = [], array $types = []): int {
5858
try {
5959
return $this->inner->executeUpdate($sql, $params, $types);
6060
} catch (Exception $e) {
61-
throw DbalException::wrap($e);
61+
throw DbalException::wrap($e, '', $sql);
6262
}
6363
}
6464

6565
public function executeStatement($sql, array $params = [], array $types = []): int {
6666
try {
6767
return $this->inner->executeStatement($sql, $params, $types);
6868
} catch (Exception $e) {
69-
throw DbalException::wrap($e);
69+
throw DbalException::wrap($e, '', $sql);
7070
}
7171
}
7272

lib/private/DB/Exceptions/DbalException.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,29 @@
3535
class DbalException extends Exception {
3636
/** @var \Doctrine\DBAL\Exception */
3737
private $original;
38+
public readonly ?string $query;
3839

3940
/**
4041
* @param \Doctrine\DBAL\Exception $original
4142
* @param int $code
4243
* @param string $message
4344
*/
44-
private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message) {
45+
private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message, ?string $query = null) {
4546
parent::__construct(
4647
$message,
4748
$code,
4849
$original
4950
);
5051
$this->original = $original;
52+
$this->query = $query;
5153
}
5254

53-
public static function wrap(\Doctrine\DBAL\Exception $original, string $message = ''): self {
55+
public static function wrap(\Doctrine\DBAL\Exception $original, string $message = '', ?string $query = null): self {
5456
return new self(
5557
$original,
5658
is_int($original->getCode()) ? $original->getCode() : 0,
57-
empty($message) ? $original->getMessage() : $message
59+
empty($message) ? $original->getMessage() : $message,
60+
$query,
5861
);
5962
}
6063

0 commit comments

Comments
 (0)