sqls 文件内容
/*xxx*/
/*20110.query.max.database.alert.status*/
select @resourceid as resourceid,
case
when r.value is null or r.value = '' then
'00'
else
r.value
end as value
from (select max(t1.lev) as value
from resourcedba.$table t0, perfdba.alert_unclosed t1
where t0.resourceid = t1.resourceid
and t0.appsystemid = @resourceid
and t1.ltime = @time
and t1.lev is not null
and t1.lev != '99') r
代码取出sql字符串
Sql sql = dao.sqls().create(sqlId);
sql.toString();
DEBUG后发现sql输出如下
select 'NULL' as resourceid,
case
when r.value is null or r.value = '' then
'00'
else
r.value
end as value
from (select max(t1.lev) as value
from resourcedba. t0, perfdba.alert_unclosed t1
where t0.resourceid = t1.resourceid
and t0.appsystemid = 'NULL'
and t1.ltime = 'NULL'
and t1.lev is not null
and t1.lev != '99') r
疑问
- 代码中获取到的sql与sqls文件中不一致。
- 使用sql.vars().set()和sql.setParam()替换表名和设置值是可行的。
- 在union all数量较多的情况下,无法满足sql拼接。