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

Add backticks for ON DUPLICATE statement in MySQL adapter #33

Merged
merged 3 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bulk_insert/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def on_conflict_statement
' ON CONFLICT DO NOTHING'
elsif adapter_name =~ /^mysql/i && update_duplicates
update_values = @columns.map do |column|
"#{column.name}=VALUES(#{column.name})"
"`#{column.name}`=VALUES(`#{column.name}`)"
end.join(', ')
' ON DUPLICATE KEY UPDATE ' + update_values
else
Expand Down
4 changes: 2 additions & 2 deletions test/bulk_insert/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class BulkInsertWorkerTest < ActiveSupport::TestCase

mysql_worker.add ["Yo", 15, false, nil, nil]

assert_equal mysql_worker.compose_insert_query, "INSERT IGNORE INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,'f',NULL,NULL,'chartreuse') ON DUPLICATE KEY UPDATE greeting=VALUES(greeting), age=VALUES(age), happy=VALUES(happy), created_at=VALUES(created_at), updated_at=VALUES(updated_at), color=VALUES(color)"
assert_equal mysql_worker.compose_insert_query, "INSERT IGNORE INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,'f',NULL,NULL,'chartreuse') ON DUPLICATE KEY UPDATE `greeting`=VALUES(`greeting`), `age`=VALUES(`age`), `happy`=VALUES(`happy`), `created_at`=VALUES(`created_at`), `updated_at`=VALUES(`updated_at`), `color`=VALUES(`color`)"
end

test "adapter dependent Mysql2Spatial methods" do
Expand Down Expand Up @@ -337,6 +337,6 @@ class BulkInsertWorkerTest < ActiveSupport::TestCase
mysql_worker.adapter_name = 'MySQL'
mysql_worker.add ["Yo", 15, false, nil, nil]

assert_equal mysql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,'f',NULL,NULL,'chartreuse') ON DUPLICATE KEY UPDATE greeting=VALUES(greeting), age=VALUES(age), happy=VALUES(happy), created_at=VALUES(created_at), updated_at=VALUES(updated_at), color=VALUES(color)"
assert_equal mysql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,'f',NULL,NULL,'chartreuse') ON DUPLICATE KEY UPDATE `greeting`=VALUES(`greeting`), `age`=VALUES(`age`), `happy`=VALUES(`happy`), `created_at`=VALUES(`created_at`), `updated_at`=VALUES(`updated_at`), `color`=VALUES(`color`)"
end
end