You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using mysql2 as the underlying driver, dealing with a table that has a multi-column primary key, multi_insert tries to get back the primary key from the inserts. However, since this is a multi-column PK, LAST_INSERT_ID() has 0, so relation.multi_insert will give back an array of 0.
multi_insert will in turn, try to query the relation with the primary keys it got back. It uses relation.primary_key for this, which will return as far as I can understand the first field of the PK. If the PK has a varchar as the first field, this will result in a query such as SELECT * FROM relation where varchar_field in (0, 0, 0...), which in mysql will return every field in the table.
To Reproduce
Create a table which contain more than one column as primary key, such as:
CREATE TABLE `my_table` (
`my_field1` varchar(255) NOT NULL,
`my_field2` varchar(255) NOT NULL,
PRIMARY KEY (`my_field1`, `my_field2`)
)
Insert random data in the created able.
Try to insert more than one value in this table using something like so:
I reckon this is a known problem with composite primary keys. In rom 6.0 you'll have "void commands" that don't return anything and you'll be able to use whatever method you want to retrieve inserted data.
@flash-gordon maybe we should raise an error in case of a command that return results automatically + composite PKs?
Describe the bug
When using mysql2 as the underlying driver, dealing with a table that has a multi-column primary key, multi_insert tries to get back the primary key from the inserts. However, since this is a multi-column PK,
LAST_INSERT_ID()
has0
, sorelation.multi_insert
will give back an array of0
.multi_insert will in turn, try to query the relation with the primary keys it got back. It uses
relation.primary_key
for this, which will return as far as I can understand the first field of the PK. If the PK has a varchar as the first field, this will result in a query such asSELECT * FROM relation where varchar_field in (0, 0, 0...)
, which in mysql will return every field in the table.To Reproduce
Create a table which contain more than one column as primary key, such as:
Insert random data in the created able.
Try to insert more than one value in this table using something like so:
d will contain all rows in the table, instead of only the two inserted ones.
Expected behavior
Only the two values are returned (or optionally, no values at all)
Your environment
The text was updated successfully, but these errors were encountered: