Skip to content

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

Open

Description

@kenjis

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)

Activity

  1. added
    databaseIssues or pull requests that affect the database layer
    on Nov 27, 2022
  2. changed the title [-]Dev: DatabaseException may not be thrown if query fails[/-] [+]Dev: DatabaseException may not be thrown even if query fails[/+] on Nov 27, 2022
  3. changed the title [-]Dev: DatabaseException may not be thrown even if query fails[/-] [+]Dev: DatabaseException might not be thrown even if query fails[/+] on Jan 27, 2024
  4. kenjis commented on Jan 27, 2024

    @kenjis
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    databaseIssues or pull requests that affect the database layerdev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions