如何为arel_table指定转义字符?

问题描述

我有这个有效的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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...