How do I set a parameter to a list of values in a BIRT report? -
I have a dataset with a query like this:
s.name Select, w .week_ending, w.sale from store s, weekly_sales_samuri w where s.id = w.store_id and s.id =?
I want to modify the query to allow the list of store IDs to be specified, like:
choose s.name, w.week_ending, Store s to w.sale, weekly_sales_samuri w where s.id = w.store_id and s.id IN (?)
How can I complete it in BITT? What type of parameter do I need to specify?
The easiest part is the report parameter: set the display type for the list box, then check Allow multiple Value options
Now the hard part: Unfortunately, you can not force multi-value report parameters in a dataset parameter (at least not in version 3.2, which I am using). Here is a posting on BITT World Blog: It explains how to use code plug-ins to bind multi-select report parameters in report data parameters.
Unfortunately, when I tried to do it, then it did not work. If you can get it to work, I will recommend this method; If you can not, in order to modify the query text of the optional dataset, to put all the values from the report parameters in the query on the appropriate parameters. Assume that s.id
is numeric, here's a function that can be pasted into the open event script for data source :
< Code> function fnMultiValParamSql (PmParameterName, pmSubstituteString, pmQueryText) {strParamValsSelected = reportContext.getParameterValue (pmParameterName); StrSelectedValues = ""; (Var varCounter = 0; varCounter & lt; strParamValsSelected.length; varCounter ++) {strSelectedValues + = strParamValsSelected [varCounter] .toString () + ","; } StrSelectedValues = strSelectedValues.substring (0, strSelectedValues.length-1); Return pmQueryText.replace (pmSubstituteString, strSelectedValues); }
which can then be called from the first event script for dataset , such as:
this.queryText = FnMultiValParamSql ("RPID", "0 / * rpid * /", this.queryText);
Believing that your report parameter is called rpID. You need to modify your query to look like this:
select s.name, w.week_ending, w.sale from store s, weekly_sites_samuri w where s.id = w.store_id And s .id IN (0 / * rpID * /)
is included in the 0 script so that the query scripts are valid at design time, and the dataset value will tie the report correctly; In the runtime, this hard-coded 0 will be removed.
However, this approach is potentially very dangerous because it can weaken you against attacks of SQL injection: as shown here:.
In the case of pure numerical values selected from predefined picklist, a SQL injection attack should not be possible; However, the same approach is weak, where freeform entry string is allowed for the parameter.
Comments
Post a Comment