aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/visitors
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r--lib/arel/visitors/to_sql.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 7a97b0d445..74b7dd9385 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -13,7 +13,11 @@ module Arel
private
def visit_Arel_Nodes_InsertStatement o
- "INSERT INTO #{visit o.relation}"
+ [
+ "INSERT INTO #{visit o.relation}",
+ ("(#{o.columns.map { |x| visit x }.join ', '})" unless o.columns.empty?),
+ ("VALUES (#{o.values.map { |x| quote visit x }.join ', '})" unless o.values.empty?),
+ ].compact.join ' '
end
def visit_Arel_Nodes_SelectStatement o
@@ -42,6 +46,7 @@ module Arel
def visit_Arel_Attributes_Integer o
"#{quote_table_name o.relation.name}.#{quote_column_name o.name}"
end
+ alias :visit_Arel_Attributes_String :visit_Arel_Attributes_Integer
def visit_Fixnum o; o end
alias :visit_String :visit_Fixnum
@@ -61,6 +66,10 @@ module Arel
DISPATCH[const] = method
end
+ def quote value, column = nil
+ @connection.quote value, column
+ end
+
def quote_table_name name
@connection.quote_table_name name
end