Class: Sequel::SQL::StringExpression
- Inherits:
-
ComplexExpression
- Object
- Expression
- ComplexExpression
- Sequel::SQL::StringExpression
- Defined in:
- lib/sequel_core/sql.rb
Overview
Subclass of ComplexExpression where the expression results in a text/string/varchar value in SQL.
Constant Summary
Constants inherited from ComplexExpression
ComplexExpression::BOOLEAN_OPERATOR_METHODS, ComplexExpression::INEQUALITY_OPERATORS, ComplexExpression::MATHEMATICAL_OPERATORS, ComplexExpression::N_ARITY_OPERATORS, ComplexExpression::ONE_ARITY_OPERATORS, ComplexExpression::OPERTATOR_INVERSIONS, ComplexExpression::TWO_ARITY_OPERATORS
Constants included from ColumnMethods
ColumnMethods::AS, ColumnMethods::ASC, ColumnMethods::DESC
Instance Attribute Summary
Attributes inherited from ComplexExpression
Class Method Summary collapse
-
.like(l, *ces) ⇒ Object
Creates a SQL pattern match exprssion.
Methods included from NoBooleanInputMethods
Methods included from StringConcatenationMethods
Methods included from StringMethods
Methods inherited from ComplexExpression
Methods inherited from Expression
Methods included from ColumnMethods
Class Method Details
.like(l, *ces) ⇒ Object
Creates a SQL pattern match exprssion. left (l) is the SQL string we are matching against, and ces are the patterns we are matching. The match succeeds if any of the patterns match (SQL OR). Patterns can be given as strings or regular expressions. Strings will cause the SQL LIKE operator to be used, and should be supported by most databases. Regular expressions will probably only work on MySQL and PostgreSQL, and SQL regular expression syntax is not fully compatible with ruby regular expression syntax, so be careful if using regular expressions.
The pattern match will be case insensitive if the last argument is a hash with a key of :case_insensitive that is not false or nil. Also, if a case insensitive regular expression is used (//i), that particular pattern which will always be case insensitive.
411 412 413 414 415 416 417 418 |
# File 'lib/sequel_core/sql.rb', line 411 def self.like(l, *ces) case_insensitive = ces.[:case_insensitive] ces.collect! do |ce| op, expr = Regexp === ce ? [ce.casefold? || case_insensitive ? :'~*' : :~, ce.source] : [case_insensitive ? :ILIKE : :LIKE, ce.to_s] BooleanExpression.new(op, l, expr) end ces.length == 1 ? ces.at(0) : BooleanExpression.new(:OR, *ces) end |