使用Sql对象时,遇到下面这种SQL写法,如果按文档说的,得到的结果并不正确 。
Sql sql = DbUtils.getSqlFromFile("db/att_stat.sql", "ANOMALY.ListRecord")
.setVar("entry_in", "1")
.setVar("entry_out", "2");
/* ANOMALY.ListRecord */
SELECT t.*
FROM att_record AS t
WHERE id IN (SELECT max(id)
FROM att_record
WHERE create_time >= @startTime AND create_time < @endTime
AND person_type = @personType
AND class_id in (SELECT class_id FROM att_stat_class)
GROUP BY person_id
HAVING string_agg(entry_type,'') LIKE '%$entry_in$entry_in%' OR string_agg(entry_type,'') LIKE '%$entry_out$entry_out%'
)
ORDER BY t.person_id
得到的LIKE其实是这样的
HAVING string_agg(entry_type,'') LIKE '%1entry_in%' OR string_agg(entry_type,'') LIKE '%2entry_out%'
如果把SQL写成
HAVING string_agg(entry_type,'') LIKE '%$entry_in$$entry_in$%' OR string_agg(entry_type,'') LIKE '%$entry_out$$entry_out$%'
那结果就是对的。
貌似VAR的写法在遇到两个连续的VAR时,是需要用$包起来才行的。
这算是个BUG么?