How do I set a parameter to a list of values in a BIRT report?

前端 未结 4 845

I have a DataSet with a query like this:

select s.name, w.week_ending, w.sales 
from store s, weekly_sales_summary w 
where s.id=w.store_id and s.id = ?
         


        
4条回答
  •  广开言路
    2020-12-03 04:47

    Here's another one. Based on some hints I found elsewhere and extended to preserve the number of parameters in your data set SQL. This solution works with a JavaScript function that you call at OnBeforeOpen of the data set:

    prepare(this);
    
    function prepare(dataSet) {
        while (dataSet.queryText.indexOf("@IN?")>=0) {
            dataSet.queryText = dataSet.queryText.replace(
                "@XYZ?", 
                "('"+params["products"].value.join("','")+"') or ?=0"
            );
        }
    }
    

    In your query, replace occurrences of (?) with @XYZ?. The method above makes sure that the query has the actual values and still a parameter (so that the dataset editor and preview doesn't complain).

    Note: Beware of SQL injection, e.g. by not allowing string values

提交回复
热议问题