Skip to content

Commit 5504162

Browse files
committed
fix: throw Postgre query errors with warnings disabled (#6913)
1 parent 744e717 commit 5504162

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎system/Database/Postgre/Connection.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,13 @@ public function getVersion(): string
207207
protected function execute(string $sql)
208208
{
209209
try {
210-
return pg_query($this->connID, $sql);
210+
$result = pg_query($this->connID, $sql);
211+
212+
if ($result === false && $this->DBDebug) {
213+
throw new DatabaseException((string) pg_last_error($this->connID));
214+
}
215+
216+
return $result;
211217
} catch (ErrorException $e) {
212218
$trace = array_slice($e->getTrace(), 2); // remove the call to error handler
213219

‎tests/system/Database/Live/BadQueryTest.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,22 @@ public function testBadQueryDebugFalse(): void
5353

5454
$this->enableDBDebug();
5555
}
56+
57+
public function testPostgreBadQueryDebugTrueWithWarningsDisabled(): void
58+
{
59+
if ($this->db->DBDriver !== 'Postgre') {
60+
$this->markTestSkipped('This test is only for Postgre.');
61+
}
62+
63+
$this->enableDBDebug();
64+
$errorReporting = error_reporting(E_ALL & ~E_WARNING);
65+
66+
try {
67+
$this->expectException(DatabaseException::class);
68+
$this->expectExceptionMessage('table_does_not_exist');
69+
$this->db->query('SELECT * FROM table_does_not_exist');
70+
} finally {
71+
error_reporting($errorReporting);
72+
}
73+
}
5674
}

0 commit comments

Comments
 (0)