Skip to content

Commit

Permalink
Escape columns in DUPLICATE KEY statements (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelStrother authored and nettofarah committed Aug 20, 2016
1 parent 54661e7 commit d3c22e7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/polo/adapters/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def on_duplicate_key_update(inserts, records)
insert_and_record = inserts.zip(records)
insert_and_record.map do |insert, record|
values_syntax = record.attributes.keys.map do |key|
"#{key} = VALUES(#{key})"
"`#{key}` = VALUES(`#{key}`)"
end

on_dup_syntax = "ON DUPLICATE KEY UPDATE #{values_syntax.join(', ')}"
Expand Down
2 changes: 1 addition & 1 deletion spec/adapters/mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
describe '#on_duplicate_key_update' do
it 'appends ON DUPLICATE KEY UPDATE with all values to the current INSERT statement' do
insert_netto = [
%q{INSERT INTO "chefs" ("id", "name", "email") VALUES (1, 'Netto', '[email protected]') ON DUPLICATE KEY UPDATE id = VALUES(id), name = VALUES(name), email = VALUES(email)}
%q{INSERT INTO "chefs" ("id", "name", "email") VALUES (1, 'Netto', '[email protected]') ON DUPLICATE KEY UPDATE `id` = VALUES(`id`), `name` = VALUES(`name`), `email` = VALUES(`email`)}
]

inserts = translator.inserts
Expand Down

0 comments on commit d3c22e7

Please sign in to comment.