module Sequel::Dataset::SplitArrayNil

  1. lib/sequel/extensions/split_array_nil.rb

Methods

Public Instance

  1. complex_expression_sql_append

Public Instance methods

complex_expression_sql_append(sql, op, args)

Over the IN/NOT IN handling with an array of values where one of the values in the array is nil, by removing nils from the array of values, and using a separate OR IS NULL clause for IN or AND IS NOT NULL clause for NOT IN.

[show source]
   # File lib/sequel/extensions/split_array_nil.rb
51 def complex_expression_sql_append(sql, op, args)
52 case op
53 when :IN, :"NOT IN"
54   vals = args[1]
55   if (vals.is_a?(Array) || vals.is_a?(Set)) && vals.any?(&:nil?)
56     cols = args[0]
57     if vals.is_a?(Set)
58       vals = vals.dup
59       vals.delete(nil)
60     else
61       vals = vals.compact
62     end
63     c = Sequel::SQL::BooleanExpression
64     if op == :IN
65       literal_append(sql, c.new(:OR, c.new(:IN, cols, vals), c.new(:IS, cols, nil)))
66     else
67       literal_append(sql, c.new(:AND, c.new(:"NOT IN", cols, vals), c.new(:"IS NOT", cols, nil)))
68     end
69   else
70     super
71   end
72 else
73   super
74 end
75 end