Skip to content

rawQuery not throwing an Exception on a Transaction #829

Open
@GuiTessari

Description

@GuiTessari

Hello,

I'm using rawQuery() with transaction and after some tests I realized that even if one insert fails the commit will happen.
This is a simple example:

CREATE TABLE test (
id int(8)
);

try{
$this->mysqlidb->startTransaction();

    $this->mysqlidb->insert("test", Array("id" => 1));
    //$this->mysqlidb->insert("test", Array("id" => 1, "test" => 2)); -> Throwing an Exception
    //$sql = "insert into test(id, test) values (1, 2)"; -> Throwing an Exception
    $sql1 = "insert into test (select 1, 2 from dual)"; -> Not throwing an Exception
    $this->mysqlidb->rawQuery($sql1);

    $this->mysqlidb->commit();

    print_r($this->mysqlidb->get("test", null, "id"));

} catch (Exception $e) {
echo $e->getMessage();
}

So, after execute this it will insert the id 1 even though the second insert returns an error.
It probably will be fixed by adding some verification after $stmt->execute(); in the rawQuery function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions