问题描述
我有这个有效的SQL查询:
SELECT DISTINCT "SIGN_UPS"."EMAIL" FROM "SIGN_UPS" WHERE (LOWER("SIGN_UPS"."EMAIL") LIKE 'amado\_bartell' ESCAPE '\');
但是它仅适用于ESCAPE '\'
,没有返回任何内容。
我的rails代码是:
where arel_table['email'].lower.matches(sanitize_sql_like("amado_bartell")).to_sql
这会在SQL中生成除转义符之外的所有内容,而且我不知道如何使它包含转义子句。如何获得Arel表来定义转义符?
解决方法
matches
的源代码为:
def matches other,escape = nil,case_sensitive = false
Nodes::Matches.new self,quoted_node(other),escape,case_sensitive
end
因此,通过添加第二个参数,可以指定一个转义子句:
where arel_table['email'].lower.matches(sanitize_sql_like("amado_bartell"),'\\').to_sql