aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/insert_manager.rb3
-rw-r--r--lib/arel/visitors/to_sql.rb11
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/arel/insert_manager.rb b/lib/arel/insert_manager.rb
index bfd3034df4..d6c663a9c4 100644
--- a/lib/arel/insert_manager.rb
+++ b/lib/arel/insert_manager.rb
@@ -9,5 +9,8 @@ module Arel
@head.relation = table
self
end
+
+ def columns; @head.columns end
+ def values; @head.values end
end
end
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