Skip to content

Bug: Return value in Database::table()->insert() without autoincrement on PK #41

Description

@insekticid

https://github.com/nette/database/blob/master/src/Database/Table/Selection.php#L742

$primaryKey = $this->context->getInsertId() aka PDO::lastInsertId()

you have table:
id int(10) unsigned NOT NULL
value varchar(255) COLLATE utf8_czech_ci DEFAULT NULL
PRIMARY KEY (id),

Database::table()->insert(array('id'=>2, 'value'=> 'text'));
will result in
PDO::lastInsertId() return 0 because we have not autoincrement on the table
https://github.com/nette/database/blob/master/src/Database/Table/Selection.php#L769

$row = $this->createSelectionInstance()
            ->select('*')
            ->wherePrimary(0)
            ->fetch();

solution?
check no autoincrement on PK and then iterate over data to insert and get primary key value from this array?

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions