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
59 def is_distinct_from_sql_append(sql, idf)
60   lhs = idf.lhs
61   rhs = idf.rhs
62 
63   if supports_is_distinct_from?
64     sql << "("
65     literal_append(sql, lhs)
66     sql << " IS DISTINCT FROM "
67     literal_append(sql, rhs)
68     sql << ")"
69   elsif db.database_type == :derby && (lhs == nil || rhs == nil)
70     if lhs == nil && rhs == nil
71       sql << literal_false
72     elsif lhs == nil
73       literal_append(sql, ~Sequel.expr(rhs=>nil))
74     else
75       literal_append(sql, ~Sequel.expr(lhs=>nil))
76     end
77   else
78     literal_append(sql, Sequel.case({(Sequel.expr(lhs=>rhs) | [[lhs, nil], [rhs, nil]]) => 0}, 1) => 1)
79   end
80 end