diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-13 18:55:15 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-13 18:55:15 -0700 |
commit | 74a27a0d83ecd7ed4975851ea92ee517a1581faf (patch) | |
tree | b120548f12566bd6a9c32a142c6191ae17eadf38 /lib/arel/visitors | |
parent | 9fc70e22f9bf7df8485b90b3d7e4a5c58cb0ebbb (diff) | |
download | rails-74a27a0d83ecd7ed4975851ea92ee517a1581faf.tar.gz rails-74a27a0d83ecd7ed4975851ea92ee517a1581faf.tar.bz2 rails-74a27a0d83ecd7ed4975851ea92ee517a1581faf.zip |
inserts have the correct syntax
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 74b7dd9385..d47c621f6a 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -15,8 +15,15 @@ module Arel def visit_Arel_Nodes_InsertStatement o [ "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?), + + ("(#{o.columns.map { |x| + quote_column_name x.name + }.join ', '})" unless o.columns.empty?), + + ("VALUES (#{o.values.map { |value| + value ? quote(visit(value)) : 'NULL' + }.join ', '})" unless o.values.empty?), + ].compact.join ' ' end @@ -43,12 +50,15 @@ module Arel "#{visit o.left} = #{visit o.right}" end - def visit_Arel_Attributes_Integer o + def visit_Arel_Attributes_Attribute o "#{quote_table_name o.relation.name}.#{quote_column_name o.name}" end - alias :visit_Arel_Attributes_String :visit_Arel_Attributes_Integer + alias :visit_Arel_Attributes_Integer :visit_Arel_Attributes_Attribute + alias :visit_Arel_Attributes_String :visit_Arel_Attributes_Attribute + alias :visit_Arel_Attributes_Time :visit_Arel_Attributes_Attribute def visit_Fixnum o; o end + alias :visit_Time :visit_Fixnum alias :visit_String :visit_Fixnum alias :visit_Arel_Nodes_SqlLiteral :visit_Fixnum alias :visit_Arel_SqlLiteral :visit_Fixnum # This is deprecated |