695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
|
# File 'lib/sequel/adapters/shared/mysql.rb', line 695
def complex_expression_sql_append(sql, op, args)
case op
when :IN, :"NOT IN"
ds = args[1]
if ds.is_a?(Sequel::Dataset) && ds.opts[:limit]
super(sql, op, [args[0], ds.from_self])
else
super
end
when :~, :'!~', :'~*', :'!~*', :LIKE, :'NOT LIKE', :ILIKE, :'NOT ILIKE'
if !db.mariadb? && db.server_version >= 80000 && [:~, :'!~'].include?(op)
func = Sequel.function(:REGEXP_LIKE, args[0], args[1], 'c')
func = ~func if op == :'!~'
return literal_append(sql, func)
end
sql << '('
literal_append(sql, args[0])
sql << ' '
sql << 'NOT ' if [:'NOT LIKE', :'NOT ILIKE', :'!~', :'!~*'].include?(op)
sql << ([:~, :'!~', :'~*', :'!~*'].include?(op) ? 'REGEXP' : 'LIKE')
sql << ' '
sql << 'BINARY ' if [:~, :'!~', :LIKE, :'NOT LIKE'].include?(op)
literal_append(sql, args[1])
if [:LIKE, :'NOT LIKE', :ILIKE, :'NOT ILIKE'].include?(op)
sql << " ESCAPE "
literal_append(sql, "\\")
end
sql << ')'
when :'||'
if args.length > 1
sql << "CONCAT"
array_sql_append(sql, args)
else
literal_append(sql, args[0])
end
when :'B~'
sql << "CAST(~"
literal_append(sql, args[0])
sql << " AS SIGNED INTEGER)"
else
super
end
end
|