NutzCN Logo
问答 dao的var占位符的一点问题
发布于 1957天前 作者 jirongjun 1979 次浏览 复制 上一个帖子 下一个帖子
标签:

使用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么?

11 回复

额,看是有可能

这个bug在新版本中解决了吧?我们之前已经写的自定义sql需要做什么修改吗?Nutz Dao是无感修复的吧,赞!@wendal

新版加了 ${abc} @{xxx} 这样写

@wendal ${abc}和@{xxx}之间要有个空格?下面4种写法都可以吗?
${abc}@{xxx}
@{xxx}${abc}
${abc}${abc}
@{xxx}@{xxx}

不需要空格

@wendal 那我升到新版本之后,我原来的SQL不用改,继续用我说的那种$xxxx$,也是可以的吧。

添加回复
请先登陆
回到顶部