Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
insekticid opened this issue Nov 7, 2014 · 1 comment

Comments

@insekticid
Copy link
Contributor

@insekticid insekticid commented Nov 7, 2014

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?

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Mar 26, 2015

Can you prepare PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.