Module: Sequel::SQL::IsDistinctFrom::DatasetMethods

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

Overview

These methods are added to datasets using the is_distinct_from extension extension, for the purposes of correctly literalizing IsDistinctFrom expressions for the appropriate database type.

Instance Method Summary collapse

Instance Method Details

#is_distinct_from_sql_append(sql, idf) ⇒ Object

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

[View source]

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