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
46 def complex_expression_sql_append(sql, op, args)
47 case op
48 when :IN, :"NOT IN"
49   vals = args[1]
50   if vals.is_a?(Array) && vals.any?(&:nil?)
51     cols = args[0]
52     vals = vals.compact
53     c = Sequel::SQL::BooleanExpression
54     if op == :IN
55       literal_append(sql, c.new(:OR, c.new(:IN, cols, vals), c.new(:IS, cols, nil)))
56     else
57       literal_append(sql, c.new(:AND, c.new(:"NOT IN", cols, vals), c.new(:"IS NOT", cols, nil)))
58     end
59   else
60     super
61   end
62 else
63   super
64 end
65 end