database icon indicating copy to clipboard operation
database copied to clipboard

mysql: insert when primary key is not auto_increment

Open Hajneej opened this issue 9 years ago • 2 comments

When inserting record to table with primary key column without auto_increment, the result of operation is false. The reason is that it is not able to refetch data. It is because the current solution is relying on LAST_INSERT_ID() sql query, which is working only for auto_increment columns (docs).

Proposed solution When table has not primary key with auto_increment, it has to be in data passed to insert method. So the solution should be that when the primary key is already set, no getLastInsertId method is needed to be called and refetch can use the primary id from data.

Hajneej avatar Jul 22 '15 11:07 Hajneej

Duplicate: #41

Can you send PR? :)

matej21 avatar Jul 22 '15 11:07 matej21

sorry for duplicate, I have to be blind or something... Ok, I will send PR for that issue

Hajneej avatar Jul 22 '15 12:07 Hajneej