Multi_insert returns more results than expected in some specific conditions
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start by tracing relation.multi_insert and the relation.primary_key lookup described in the issue, then reproduce the behavior with the provided composite-key MySQL schema and create command. Done means the command returns only the inserted rows, or no rows if that behavior is chosen, rather than every row in the table.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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() 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:
new_values = [{my_field1: "abc", my_field2: "cde"}, {my_field1: "gde", my_field2: "zyx"}]
create_cmd = my_table.command(:create, result: :many)
d = create_cmd.call(new_values)
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
- Affects my production application: No, we rolled back our change and we're going straight to the db.
- Ruby version: 2.6
- OS: Linux
- Rom-sql 3.1.0
- Rom-core 5.1.2
- Ngôn ngữ chính
- Ruby
- Star
- 220
- Fork
- 97
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rom-rb/rom-sql
-
bug help wanted
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
-
bug help wanted
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
Relation#last removes combinesĐang mởbug help wanted
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
-
bug help wanted
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
-
bug help wanted
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Tất cả issue của rom-rb/rom-sql
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
swombat/souls-house#795 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
allow favicon to be served from CDN/CORS (i.e. treat it the same as the avatar)Có thể đã có người làm @enkaskal đã nhận hôm nay. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
cotes2020/jekyll-theme-chirpy#2811 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Add a dark modeĐang mởaccessibility enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
samiromer2/Ruby-Consent-Portal#35 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100