aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-04-09 15:18:43 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-04-09 15:18:43 -0700
commite33c568f5e07e8caf7d36e8a8ca1a793b1781dc4 (patch)
treed5afcef3cd116fed45b67d05463264064da538d4 /lib
parentf81965509d74a4607ecbc3cc6f91c2ca22919f3a (diff)
downloadrails-e33c568f5e07e8caf7d36e8a8ca1a793b1781dc4.tar.gz
rails-e33c568f5e07e8caf7d36e8a8ca1a793b1781dc4.tar.bz2
rails-e33c568f5e07e8caf7d36e8a8ca1a793b1781dc4.zip
fix bind values in insert statements
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/visitors/mysql.rb8
-rw-r--r--lib/arel/visitors/to_sql.rb12
2 files changed, 12 insertions, 8 deletions
diff --git a/lib/arel/visitors/mysql.rb b/lib/arel/visitors/mysql.rb
index 92348ca7e3..70a37582c2 100644
--- a/lib/arel/visitors/mysql.rb
+++ b/lib/arel/visitors/mysql.rb
@@ -55,18 +55,18 @@ module Arel
collector = visit o.relation, collector
unless o.values.empty?
- collector << "SET "
+ collector << " SET "
collector = inject_join o.values, collector, ', '
end
unless o.wheres.empty?
- collector << "SET "
+ collector << " WHERE "
collector = inject_join o.wheres, collector, ' AND '
end
unless o.orders.empty?
- collector << "ORDER BY "
- collector = inject_join o.wheres, collector, ', '
+ collector << " ORDER BY "
+ collector = inject_join o.orders, collector, ', '
end
if o.limit
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 9cda88454b..5604b9de04 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -178,13 +178,17 @@ module Arel
def visit_Arel_Nodes_Values o, collector
collector << "VALUES ("
- collector << o.expressions.zip(o.columns).map { |value, attr|
+ len = o.expressions.length - 1
+ o.expressions.zip(o.columns).each_with_index { |(value, attr), i|
if Nodes::SqlLiteral === value
- value
+ collector = visit value, collector
else
- quote(value, attr && column_for(attr))
+ collector << quote(value, attr && column_for(attr)).to_s
end
- }.join(', ')
+ unless i == len
+ collector << ', '
+ end
+ }
collector << ")"
end