Skip to content

Commit a19128b

Browse files
committed
fix: trigger DBQuery is not fired when query error and DBDebug is true
1 parent 89223f7 commit a19128b

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

phpstan-baseline.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ parameters:
137137

138138
-
139139
message: "#^Negated boolean expression is always true\\.$#"
140-
count: 1
140+
count: 2
141141
path: system/Database/BaseConnection.php
142142

143143
-

system/Database/BaseConnection.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Closure;
1515
use CodeIgniter\Database\Exceptions\DatabaseException;
1616
use CodeIgniter\Events\Events;
17+
use Exception;
1718
use stdClass;
1819
use Throwable;
1920

@@ -603,7 +604,14 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s
603604
$this->lastQuery = $query;
604605

605606
// Run the query for real
606-
if (! $this->pretend && false === ($this->resultID = $this->simpleQuery($query->getQuery()))) {
607+
try {
608+
$exception = null;
609+
$this->resultID = $this->simpleQuery($query->getQuery());
610+
} catch (Exception $exception) {
611+
$this->resultID = false;
612+
}
613+
614+
if (! $this->pretend && $this->resultID === false) {
607615
$query->setDuration($startTime, $startTime);
608616

609617
// This will trigger a rollback if transactions are being used
@@ -626,6 +634,15 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s
626634
}
627635
}
628636

637+
if (! $this->pretend) {
638+
// Let others do something with this query.
639+
Events::trigger('DBQuery', $query);
640+
}
641+
642+
if ($exception !== null) {
643+
throw $exception;
644+
}
645+
629646
return false;
630647
}
631648

0 commit comments

Comments
 (0)