Skip to content

Commit fba4362

Browse files
authored
fix: throw Postgre query errors with warnings disabled (#10573)
* fix: throw Postgre query errors with warnings disabled (#6913) * style: satisfy Rector for Postgre errors (#6913) * docs: add changelog entry for Postgre query errors (#6913)
1 parent 28bb14c commit fba4362

3 files changed

Lines changed: 26 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(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
}

‎user_guide_src/source/changelogs/v4.7.5.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Bugs Fixed
5353
- **Cookie:** Fixed a bug where ``Cookie`` instances created with ``raw: true`` allowed invalid characters in cookie values rejected by ``setrawcookie()``.
5454
- **Cookie:** Fixed a bug where ``Cookie`` instances allowed invalid characters in path, domain, and prefix attributes rejected by ``setcookie()`` and ``setrawcookie()``.
5555
- **Database:** Fixed a bug where rebuilding a SQLite3 table (e.g., ``Forge::dropColumn()``, ``Forge::modifyColumn()``, ``Forge::dropForeignKey()`` and ``Forge::dropPrimaryKey()``) corrupted the table names referenced by its foreign keys when ``DBPrefix`` was set.
56+
- **Database:** Fixed a bug where Postgre query failures were silently ignored when ``DBDebug`` was enabled and PHP warnings were disabled. A ``DatabaseException`` is now thrown.
5657
- **Debug:** Fixed a bug where ``Timer::start()`` treated ``0.0`` as an empty value and substituted the current time.
5758
- **Files:** Fixed a bug where ``File::move()`` and ``UploadedFile::move()`` set executable and overly permissive file permissions (``0777 & ~umask()`` instead of ``0666 & ~umask()``), and ``UploadedFile::move()`` targeted the parent directory instead of the destination file for ``chmod()``.
5859
- **Helpers:** Fixed a bug where ``get_dir_file_info()`` returned incomplete entries for subdirectories and missing files instead of omitting them.

0 commit comments

Comments
 (0)