Method: Sequel::SQL::IsDistinctFrom::DatasetMethods#is_distinct_from_sql_append

Defined in:
lib/sequel/extensions/is_distinct_from.rb

#is_distinct_from_sql_append(sql, idf) ⇒ Object

Append the SQL fragment for the IS DISTINCT FROM expression to the SQL query.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sequel/extensions/is_distinct_from.rb', line 59

def is_distinct_from_sql_append(sql, idf)
  lhs = idf.lhs
  rhs = idf.rhs

  if supports_is_distinct_from?
    sql << "("
    literal_append(sql, lhs)
    sql << " IS DISTINCT FROM "
    literal_append(sql, rhs)
    sql << ")"
  elsif db.database_type == :derby && (lhs == nil || rhs == nil)
    if lhs == nil && rhs == nil
      sql << literal_false
    elsif lhs == nil
      literal_append(sql, ~Sequel.expr(rhs=>nil))
    else
      literal_append(sql, ~Sequel.expr(lhs=>nil))
    end
  else
    literal_append(sql, Sequel.case({(Sequel.expr(lhs=>rhs) | [[lhs, nil], [rhs, nil]]) => 0}, 1) => 1)
  end
end