class Sequel::SQL::ComplexExpression
def initialize(op, *args)
Raise an +Error+ if the operator doesn't allow boolean input and a boolean argument is given.
other than the second arg for an IN/NOT IN operator.
Convert all args that are hashes or arrays of two element arrays to +BooleanExpressions+,
Set the operator symbol and arguments for this object to the ones given.
def initialize(op, *args) orig_args = args args = args.map{|a| Sequel.condition_specifier?(a) ? SQL::BooleanExpression.from_value_pairs(a) : a} case op when *N_ARITY_OPERATORS raise(Error, "The #{op} operator requires at least 1 argument") unless args.length >= 1 args.map!{|a| a.is_a?(self.class) && a.op == :NOOP ? a.args.first : a} if ASSOCIATIVE_OPERATORS.include?(op) old_args = args args = [] old_args.each{|a| a.is_a?(self.class) && a.op == op ? args.concat(a.args) : args.push(a)} end when *TWO_ARITY_OPERATORS raise(Error, "The #{op} operator requires precisely 2 arguments") unless args.length == 2 # With IN/NOT IN, even if the second argument is an array of two element arrays, # don't convert it into a boolean expression, since it's definitely being used # as a value list. args[1] = orig_args[1] if IN_OPERATORS.include?(op) when *ONE_ARITY_OPERATORS raise(Error, "The #{op} operator requires a single argument") unless args.length == 1 when *CUSTOM_EXPRESSIONS # nothing else raise(Error, "Invalid operator #{op}") end @op = op @args = args.freeze freeze end
def inspect_args
def inspect_args [:op, "*args"] end
def sql_boolean
def sql_boolean BooleanExpression.new(op, *args) end
def sql_number
def sql_number NumericExpression.new(op, *args) end
def sql_string
def sql_string StringExpression.new(op, *args) end