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

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
85 def supports_is_distinct_from?
86   if defined?(super)
87     return super
88   end
89 
90   case db.database_type
91   when :postgres, :h2
92     true
93   when :sqlite
94     db.sqlite_version >= 33900
95   else
96     false
97   end
98 end