Skip to content
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
8 changes: 7 additions & 1 deletion system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ public function getVersion(): string
protected function execute(string $sql)
{
try {
return pg_query($this->connID, $sql);
$result = pg_query($this->connID, $sql);

if ($result === false && $this->DBDebug) {
throw new DatabaseException(pg_last_error($this->connID));
}

return $result;
} catch (ErrorException $e) {
$trace = array_slice($e->getTrace(), 2); // remove the call to error handler

Expand Down
18 changes: 18 additions & 0 deletions tests/system/Database/Live/BadQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,22 @@ public function testBadQueryDebugFalse(): void

$this->enableDBDebug();
}

public function testPostgreBadQueryDebugTrueWithWarningsDisabled(): void
{
if ($this->db->DBDriver !== 'Postgre') {
$this->markTestSkipped('This test is only for Postgre.');
}

$this->enableDBDebug();
$errorReporting = error_reporting(E_ALL & ~E_WARNING);

try {
$this->expectException(DatabaseException::class);
$this->expectExceptionMessage('table_does_not_exist');
$this->db->query('SELECT * FROM table_does_not_exist');
} finally {
error_reporting($errorReporting);
}
}
}
Loading