diff options
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/nodes.rb | 1 | ||||
-rw-r--r-- | lib/arel/nodes/assignment.rb | 6 | ||||
-rw-r--r-- | lib/arel/update_manager.rb | 2 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 15 |
4 files changed, 21 insertions, 3 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb index 1215f3f00c..1f31219417 100644 --- a/lib/arel/nodes.rb +++ b/lib/arel/nodes.rb @@ -1,5 +1,6 @@ require 'arel/nodes/binary' require 'arel/nodes/equality' +require 'arel/nodes/assignment' require 'arel/nodes/or' require 'arel/nodes/and' require 'arel/nodes/greater_than' diff --git a/lib/arel/nodes/assignment.rb b/lib/arel/nodes/assignment.rb new file mode 100644 index 0000000000..693bd5afe6 --- /dev/null +++ b/lib/arel/nodes/assignment.rb @@ -0,0 +1,6 @@ +module Arel + module Nodes + class Assignment < Arel::Nodes::Binary + end + end +end diff --git a/lib/arel/update_manager.rb b/lib/arel/update_manager.rb index cd4342529b..484230c4e1 100644 --- a/lib/arel/update_manager.rb +++ b/lib/arel/update_manager.rb @@ -26,7 +26,7 @@ module Arel @head.values = [values] else @head.values = values.map { |column,value| - Nodes::Equality.new( + Nodes::Assignment.new( Nodes::UnqualifiedColumn.new(column), value ) diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index f70cae9430..8638bf43c3 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -149,13 +149,24 @@ module Arel "#{visit o.left} OR #{visit o.right}" end - def visit_Arel_Nodes_Equality o + def visit_Arel_Nodes_Assignment o right = o.right - # FIXME: maybe we should visit NilClass? + right = right.nil? ? 'NULL' : visit(right) "#{visit o.left} = #{right}" end + def visit_Arel_Nodes_Equality o + right = o.right + + # FIXME: maybe we should visit NilClass? + if right.nil? + "#{visit o.left} IS NULL" + else + "#{visit o.left} = #{visit right}" + end + end + def visit_Arel_Nodes_UnqualifiedColumn o "#{quote_column_name o.name}" end |