【发布时间】:2014-09-19 18:48:35
【问题描述】:
下面是我在 Jasper 报告中运行的 SQL 语句。我已经弄清楚如何通过报告参数进行动态查询。我的 fromDate 和 toDate 参数工作正常。我遇到的问题是向 WhereClause 添加额外的 SQL 并在该 SQL 中评估额外的参数。
$P!{userName_sql} 的值为
" and u.u_username = $P{userName} "
我最终得到一个 SQL 错误,因为在将 userName 参数附加到 SQL 时没有对其进行评估。我可以通过这样的连接来解决这个问题:
" and u.u_username = '" + $P{userName} + "'"
但是参数可以被SQL注入。 有没有办法让该参数在不必连接的情况下进行评估?
SQL
SELECT tw.time_dt, ca.claimaudit_no,concat(u.u_firstnm, ' ', u.u_lastnm) user, ca.ca_claimtype, tw.time_workflowqueue, sum(tw.time_minutes / 60) hrs,
(
select count(*) cnt from hcfasline hsline
where hsline.hcfa_no = phases.hcfa_no
union
select count(*) cnt from ubdtlsline dtlsline
inner join ubsline usline on usline.ubsline_no = dtlsline.ubsline_no
where usline.ub_no = phases.ub_no
order by cnt desc
limit 1
) linecnt
FROM timeworksheet tw
inner join users u on tw.users_no = u.users_no
inner join claimaudit ca on tw.claimaudit_no = ca.claimaudit_no
inner join claimauditphases phases on tw.claimauditphase_no = phases.claimauditphase_no
where tw.time_dt between $P{fromDate} and $P{toDate}$P!{userName_sql}
group by claimaudit_no, user, ca.ca_claimtype, tw.time_workflowqueue, tw.time_dt
order by user, ca.ca_claimtype
【问题讨论】:
标签: jasper-reports