database icon indicating copy to clipboard operation
database copied to clipboard

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

Open insekticid opened this issue 11 years ago • 1 comments

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?

insekticid avatar Nov 07 '14 09:11 insekticid

Can you prepare PR?

dg avatar Mar 26 '15 18:03 dg