Class | Sequel::SQL::StringExpression |
In: |
lib/sequel/sql.rb
|
Parent: | ComplexExpression |
Subclass of ComplexExpression where the expression results in a text/string/varchar value in SQL.
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.
# File lib/sequel/sql.rb, line 698 698: def self.like(l, *ces) 699: case_insensitive = (ces.last.is_a?(Hash) ? ces.pop : {})[:case_insensitive] 700: ces.collect! do |ce| 701: op, expr = Regexp === ce ? [ce.casefold? || case_insensitive ? :'~*' : :~, ce.source] : [case_insensitive ? :ILIKE : :LIKE, ce] 702: BooleanExpression.new(op, l, expr) 703: end 704: ces.length == 1 ? ces.at(0) : BooleanExpression.new(:OR, *ces) 705: end