Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev: DatabaseException might not be thrown even if query fails #6913

Open
3 tasks
kenjis opened this issue Nov 27, 2022 · 1 comment
Open
3 tasks

Dev: DatabaseException might not be thrown even if query fails #6913

kenjis opened this issue Nov 27, 2022 · 1 comment
Labels
database Issues or pull requests that affect the database layer dev

Comments

@kenjis
Copy link
Member

kenjis commented Nov 27, 2022

SQLite3, Postgres and OCI8 drivers throw ErrorException when a query error occurs
because of Error Handler. See #6912

if (error_reporting() & $severity) {
throw new ErrorException($message, 0, $severity, $file, $line);
}

So depending on the value of the error reporting setting, the ErrorException may not be thrown.

See #6886 (comment)

@kenjis kenjis added dev database Issues or pull requests that affect the database layer labels Nov 27, 2022
@kenjis kenjis changed the title Dev: DatabaseException may not be thrown if query fails Dev: DatabaseException may not be thrown even if query fails Nov 27, 2022
@kenjis kenjis changed the title Dev: DatabaseException may not be thrown even if query fails Dev: DatabaseException might not be thrown even if query fails Jan 27, 2024
@kenjis
Copy link
Member Author

kenjis commented Jan 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Issues or pull requests that affect the database layer dev
Projects
None yet
Development

No branches or pull requests

1 participant