如何为 arel_table 指定转义字符?
How to specify escape character for arel_table?
我有一个有效的 SQL 查询:
SELECT DISTINCT "SIGN_UPS"."EMAIL" FROM "SIGN_UPS" WHERE (LOWER("SIGN_UPS"."EMAIL") LIKE 'amado\_bartell' ESCAPE '\');
但它只适用于 ESCAPE '\'
,没有它 returns 什么都没有。
我的rails代码是:
where arel_table['email'].lower.matches(sanitize_sql_like("amado_bartell")).to_sql
这会生成 SQL 中的所有内容,但转义除外——我不知道如何让它包含转义子句。如何获取 arel table 来定义转义字符?
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
我有一个有效的 SQL 查询:
SELECT DISTINCT "SIGN_UPS"."EMAIL" FROM "SIGN_UPS" WHERE (LOWER("SIGN_UPS"."EMAIL") LIKE 'amado\_bartell' ESCAPE '\');
但它只适用于 ESCAPE '\'
,没有它 returns 什么都没有。
我的rails代码是:
where arel_table['email'].lower.matches(sanitize_sql_like("amado_bartell")).to_sql
这会生成 SQL 中的所有内容,但转义除外——我不知道如何让它包含转义子句。如何获取 arel table 来定义转义字符?
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