Method: Sequel::MySQL::DatasetMethods#complex_expression_sql

Defined in:
lib/sequel/adapters/shared/mysql.rb

#complex_expression_sql(op, args) ⇒ Object

MySQL specific syntax for LIKE/REGEXP searches, as well as string concatenation.



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/sequel/adapters/shared/mysql.rb', line 302

def complex_expression_sql(op, args)
  case op
  when :~, :'!~', :'~*', :'!~*', :LIKE, :'NOT LIKE', :ILIKE, :'NOT ILIKE'
    "(#{literal(args.at(0))} #{'NOT ' if [:'NOT LIKE', :'NOT ILIKE', :'!~', :'!~*'].include?(op)}#{[:~, :'!~', :'~*', :'!~*'].include?(op) ? 'REGEXP' : 'LIKE'} #{'BINARY ' if [:~, :'!~', :LIKE, :'NOT LIKE'].include?(op)}#{literal(args.at(1))})"
  when :'||'
    if args.length > 1
      "CONCAT(#{args.collect{|a| literal(a)}.join(', ')})"
    else
      literal(args.at(0))
    end
  when :'B~'
    "CAST(~#{literal(args.at(0))} AS SIGNED INTEGER)"
  else
    super(op, args)
  end
end