Class Sequel::SQL::ComplexExpression
In: lib/sequel_core/sql.rb
Parent: Expression

Represents a complex SQL expression, with a given operator and one or more attributes (which may also be ComplexExpressions, forming a tree). This class is the backbone of the blockless filter support in Sequel.

This is an abstract class that is not that useful by itself. The subclasses BooleanExpression, NumericExpression, and StringExpression define the behavior of the DSL via operators.

Methods

==   eql?   new   to_s  

Included Modules

AliasMethods CastMethods OrderMethods

Constants

OPERTATOR_INVERSIONS = {:AND => :OR, :OR => :AND, :< => :>=, :> => :<=, :<= => :>, :>= => :<, :'=' => :'!=' , :'!=' => :'=', :LIKE => :'NOT LIKE', :'NOT LIKE' => :LIKE, :~ => :'!~', :'!~' => :~, :IN => :'NOT IN', :'NOT IN' => :IN, :IS => :'IS NOT', :'IS NOT' => :IS, :'~*' => :'!~*', :'!~*' => :'~*', :NOT => :NOOP, :NOOP => :NOT, :ILIKE => :'NOT ILIKE', :'NOT ILIKE'=>:ILIKE}   A hash of the opposite for each operator symbol, used for inverting objects.
MATHEMATICAL_OPERATORS = [:+, :-, :/, :*]   Mathematical Operators used in NumericMethods
BITWISE_OPERATORS = [:&, :|, :^, :<<, :>>]   Mathematical Operators used in NumericMethods
INEQUALITY_OPERATORS = [:<, :>, :<=, :>=]   Inequality Operators used in InequalityMethods
BOOLEAN_OPERATOR_METHODS = {:& => :AND, :| =>:OR}   Hash of ruby operator symbols to SQL operators, used in BooleanMethods
TWO_ARITY_OPERATORS = [:'=', :'!=', :IS, :'IS NOT', :LIKE, :'NOT LIKE', \ :~, :'!~', :'~*', :'!~*', :IN, :'NOT IN', :ILIKE, :'NOT ILIKE'] + \ INEQUALITY_OPERATORS + BITWISE_OPERATORS   Operator symbols that take exactly two arguments
N_ARITY_OPERATORS = [:AND, :OR, :'||'] + MATHEMATICAL_OPERATORS   Operator symbols that take one or more arguments
ONE_ARITY_OPERATORS = [:NOT, :NOOP, :'B~']   Operator symbols that take one argument

Attributes

args  [R]  An array of args for this object
op  [R]  The operator symbol for this object

Public Class methods

Set the operator symbol and arguments for this object to the ones given. Convert all args that are hashes or arrays with all two pairs to ComplexExpressions. Raise an error if the operator doesn‘t allow boolean input and a boolean argument is given. Raise an error if the wrong number of arguments for a given operator is used.

[Source]

    # File lib/sequel_core/sql.rb, line 71
71:       def initialize(op, *args)
72:         args.collect! do |a|
73:           case a
74:           when Hash
75:             a.sql_expr
76:           when Array
77:             a.all_two_pairs? ? a.sql_expr : a
78:           else
79:             a
80:           end
81:         end
82:         case op
83:         when *N_ARITY_OPERATORS
84:           raise(Error, "The #{op} operator requires at least 1 argument") unless args.length >= 1
85:         when *TWO_ARITY_OPERATORS
86:           raise(Error, "The #{op} operator requires precisely 2 arguments") unless args.length == 2
87:         when *ONE_ARITY_OPERATORS
88:           raise(Error, "The #{op} operator requires a single argument") unless args.length == 1
89:         else
90:           raise(Error, "Invalid operator #{op}")
91:         end
92:         @op = op
93:         @args = args
94:       end

Public Instance methods

==( other )

Alias for eql?

Returns true if the receiver is the same expression as the the other expression.

[Source]

     # File lib/sequel_core/sql.rb, line 104
104:       def eql?( other )
105:         return other.is_a?( self.class ) &&
106:           @op.eql?( other.op ) &&
107:           @args.eql?( other.args )
108:       end

Delegate the creation of the resulting SQL to the given dataset, since it may be database dependent.

[Source]

     # File lib/sequel_core/sql.rb, line 98
 98:       def to_s(ds)
 99:         ds.complex_expression_sql(@op, @args)
100:       end

[Validate]