Skip to content

Bug: insertBatch not return false #9362

Closed
@okatse

Description

@okatse

PHP Version

8.1

CodeIgniter4 Version

4.5.1

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

PostgreSQL 15

What happened?

insertBatch never not return false

Steps to Reproduce

DataBase

CREATE TABLE public.test (
	id serial4 NOT NULL,
	"name" varchar(22) NOT NULL
);

Controller

public function test2()
{
    $db = \Config\Database::connect();
    $toInsert[] = [
        'name' => 'aaaa'
    ];
    $toInsert[] = [
        'name' => null
    ];
    try {
        $db->transBegin();
        $query = $this->db->table('public.test');
        if ($query->insertBatch($toInsert) === false) {
            d($db->error());
            d('Error from IF');
            $db->transRollback();
        }
        else
        {
            $db->transCommit();
        }
    } catch (DatabaseException $th) {
        d($th->getMessage());
        d('Error from TRY');
        $db->transRollback();
    }
}

Expected Output

$query->insertBatch($toInsert) === false

Anything else?

Without the transaction, the code works correctly. With the transaction, there is an error. pg_affected_rows(): Argument #1 ($result) must be of type PgSql\Result, bool given

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix themdatabaseIssues or pull requests that affect the database layer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions