CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

Dev: DatabaseException might not be thrown even if query fails

Open kenjis opened this issue 3 years ago • 1 comments

SQLite3, Postgres and OCI8 drivers throw ErrorException when a query error occurs because of Error Handler. See #6912 https://github.com/codeigniter4/CodeIgniter4/blob/ac1422c404a364f9493bbf1b22dacb18e3913982/system/Debug/Exceptions.php#L174-L176 So depending on the value of the error reporting setting, the ErrorException may not be thrown.

See https://github.com/codeigniter4/CodeIgniter4/pull/6886#issuecomment-1328148614

  • [ ] SQLite3 #8467
  • [ ] Postgres
  • [ ] OCI8

kenjis avatar Nov 27 '22 01:11 kenjis

SQLite3

--- a/app/Config/Boot/testing.php
+++ b/app/Config/Boot/testing.php
@@ -14,7 +14,7 @@
  | make sure they don't make it to production. And save us hours of
  | painful debugging.
  */
-error_reporting(E_ALL);
+error_reporting(E_ALL & ~E_WARNING);
 ini_set('display_errors', '1');
 
 /*
$ vendor/bin/phpunit tests/system/Database/Live/TransactionTest.php 
PHPUnit 9.6.16 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.15
Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4-4.5/phpunit.xml

F...                                                                                                                         4 / 4 (100%)

Time: 00:00.231, Memory: 18.00 MB

There was 1 failure:

1) CodeIgniter\Database\Live\TransactionTest::testTransStartDBDebugTrue
Failed asserting that null is an instance of class "CodeIgniter\Database\Exceptions\DatabaseException".

/Users/kenji/work/codeigniter/official/CodeIgniter4-4.5/tests/system/Database/Live/TransactionTest.php:106

FAILURES!
Tests: 4, Assertions: 14, Failures: 1.

SQLSRV driver has different implementation. It throws Exception when the query return value is false.

This is correct. SQLite3, Postgres and OCI8 drivers should throw Exception when the query return value is false.

kenjis avatar Jan 27 '24 04:01 kenjis