在BIRT中输入参数后更新数据集查询 [英] Updating Data Set query after parameter input in BIRT
问题描述
在BIRT报表设计中传递参数后,如何更改或更新数据集的查询?
How can I change or update a data set's query after a parameter has been passed in BIRT report designing?
详细信息:
我有一个看起来像这样的查询:
I've got a query that looks like this:
WHERE ?
该参数标记可以保存不同的值,在用户输入参数后,它看起来像这样:
That parameter marker can hold different values, after user input parameter, it would look like this e.g.:
WHERE column_name = 1
或
WHERE column_name = 2
甚至
WHERE column_name IN (1,2)
我为该数据集参数(DSP)创建了一个报告参数(RP),经过数小时的尝试,我无法更改它.
I created a Report Parameter(RP) for that Data Set Parameter(DSP) and after trying for hours, I couldn't get to change it.
我尝试过:
- 在RP和DSP上创建各种javascript表达式
- 创建一个可更改第一个RP值并返回上一步的RP
- 编辑属性绑定,尽管我无法弄清楚应该如何完成. 为了清楚起见,我正在设计一个报告,而不是将运行时集成到现有应用程序中. 我希望这很清楚,我仍在编辑问题,因此,如果您需要更多信息,请告诉我.
- Creating all sorts of javascript expressions on both, RP and DSP
- Creating a RP that would change the value of the first RP and back to previous step
- Editing the Property Binding, though I couldn't figure it out how exactly it should be done. Just to make it clear, I'm designing a report and not integrating the runtime to an existing application. I hope this is clear enough, I'm still editing the question so if you need more information just let me know.
谢谢
推荐答案
假设您使用的是Oracle DB(其他系统的行为可能有所不同),则应注意,绑定变量(以JDBC语言:问号)可以仅替换标量值,例如字符串或数字.
Assuming that you are on an Oracle DB (other systems may behave differently) you should be aware that a bind variable (in JDBC speech: the question mark) can replace a scalar value only, e.g. a string or a number.
但是您希望输入类似 list 的数字. 因此,在这种情况下,绑定变量将无济于事.
But you want something like a list of numbers as input. Thus a bind variable won't help you in this case.
可能最简单的方法来实现您想要的是:
Probably the easiest way to achieve what you want is this:
在查询中,输入:
WHERE column_name in (1) -- $REPLACE_THIS$
请注意,我在查询中使用注释作为标记.
然后,在查询的beforeOpen
事件中,如下修改查询文本:
Note that I am using a comment in the query as a marker.
Then, in the query's beforeOpen
event, modify the query text like this:
// construct a comma-separated string representation of your list
// based on your report parameter (exercise left to the reader)
// var replacement = my_to_sql_csv(params["my_report_parameter"].value);
// for demonstration use:
var replacement = "1,2";
// modify the `IN` expression inside the SQL
this.queryText = this.queryText.replaceAll("(1) -- $REPLACE_THIS$", "(" + replacement + ")";
就是这样.
这篇关于在BIRT中输入参数后更新数据集查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!