diff options
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/select_manager.rb | 2 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 18 |
2 files changed, 15 insertions, 5 deletions
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index 1728311d59..444ca8f716 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -30,7 +30,7 @@ module Arel def insert values im = InsertManager.new @engine im.insert values - raise + @engine.connection.execute im.to_sql end end end 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 |