module Sequel::SQL::IsDistinctFrom::DatasetMethods

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.

Public Instance Methods

is_distinct_from_sql_append(sql, idf) click to toggle source

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

# File lib/sequel/extensions/is_distinct_from.rb, line 58
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

Private Instance Methods

supports_is_distinct_from?() click to toggle source

Whether the database supports IS DISTINCT FROM.

Calls superclass method
# File lib/sequel/extensions/is_distinct_from.rb, line 84
def supports_is_distinct_from?
  if defined?(super)
    return super
  end

  case db.database_type
  when :postgres, :h2
    true
  when :sqlite
    db.sqlite_version >= 33900
  else
    false
  end
end