English 中文(简体)
我如何在BIRT报告中确定价值清单的参数?
原标题:How do I set a parameter to a list of values in a BIRT report?
  • 时间:2010-08-04 02:22:20
  •  标签:
  • birt

我有一个数据表,有这样一个问题:

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

我愿修改询问,以便让我具体说明一份储存识别清单,例如:

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

我如何在BIRT中做到这一点? 我需要具体说明哪些参数?

最佳回答

报告参数很容易部分:将显示类型定为清单箱,然后检查“允许多价值”办法。

Now the hard part: unfortunately, you can t bind a multi-value report parameter to a dataset parameter (at least, not in version 3.2, which is what I m using). There s a posting on the BIRT World blog here: http://birtworld.blogspot.com/2009/03/birt-multi-select-statements.html that describes how to use a code plug-in to bind multi-select report parameters to a report dataset.

不幸的是,当我尝试时,它就没有工作了。 如果你能够工作,那么我建议采用的方法;如果你能够这样做,则备选方法就是修改数据集的查询,在适当的时候将报告参数的所有价值插入询问。 假设s.id为数字,这里的功能可以过去。 公开活动说明data:

function fnMultiValParamSql ( pmParameterName, pmSubstituteString, pmQueryText )
{
strParamValsSelected=reportContext.getParameterValue(pmParameterName);
strSelectedValues="";
for (var varCounter=0;varCounter<strParamValsSelected.length;varCounter++)
{
    strSelectedValues += strParamValsSelected[varCounter].toString()+",";
}
strSelectedValues = strSelectedValues.substring(0,strSelectedValues.length-1);
return pmQueryText.replace(pmSubstituteString,strSelectedValues);
}

之后可以要求 开放式dataset,如:

this.queryText = fnMultiValParamSql ( "rpID", "0 /*rpID*/", this.queryText );

假设你的报告参数被称作微额信贷。 您将需要修改你的意见,以便考虑:

select s.name, w.week_ending, w.sales 
from store s, weekly_sales_summary w 
where s.id=w.store_id and s.id IN (0 /*rpID*/)

表中列有0份,以便查询书在设计时间有效,数据集数值将正确与报告挂钩;在操作时间,将删除这一硬编码0。

然而,这种做法可能非常危险,因为它可能使你易受注射攻击:,如下文所示:。 http://xkcd.com/327/

在从预先界定的列单中挑选出的纯数字数值的情况下,不得进行克射攻击;然而,如果允许对参数进行自由格式的立体,则同样的做法是脆弱的。

问题回答

FYI:the BIRT World article should work (I written it) but that was an early Solutions to the problem.

我们创造了一个开放的原始来源,你可以补充BIRT,为这一问题找到更清洁的解决办法。 单功能平衡中的双功能参数提供了从多价值参数中进行多功能的简单方法。

如果你仍然有兴趣查阅关于Eclipserak的“侵权行为-lib”项目

这里是另一个。 根据一些方面,我发现别处,并延伸到保留数据组中的参数。 这一解决办法与 Java本功能有关,你在数据集的OnBeforeOpen呼吁:

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).

注:通过不容许扼制价值观来认识Kalk注入。

我提出了一个更为一般性的解决办法,处理optional/required criteria的行为。 如果不需要参数,用户则不选择任何价值,国家残疾人协会便会残疾。 它还允许用户选择实际价值和无效价值。

在报告<代码>中,初始 文字一添加本法典:

/** Fullfill IN-clause in a data set query,
 *  using a List box report parameter.
 *  Placeholder must be the parentheses after IN keyword with wathever you want inside.
 *  If required is false then the whole IN-clause in the query 
 *  must be surrounded by parentheses.
 *  dataType and required refers to the parameter, they must be passed, 
 *  but should be better to find a way to retrieve them inside this function
 *  (given parameter name).
 */
function fulfillInClause(dataSet, placeholder, param, dataType, required) {

    if (dataSet.queryText.indexOf(placeholder)>=0) {

        var paramValue = params[param].value;
        var emptyParam = (paramValue==null || paramValue.length<=0);

        //build the list of possible values
        //  paramValue==null check in ternary operators 
        //  will prevent exceptions when user doesn t select any value
        //  (it will not affect the query if param is optional, 
        //  while we will never arrive here if it is required)
        var replacement = " (";
        if (dataType == "string")
            replacement += (emptyParam ? "  " : createList(paramValue, ",", " ", "varchar(10)") );
        else if (dataType == "integer")
            replacement += (emptyParam ? "0"  : createList(paramValue, ",", "" , "int"        ) );
        else
            //TODO implement more cases
            return;
        replacement += ") ";

        //if param is not required and user doesn t select any value for it
        //then nullify the IN clause with an always-true clause
        if (!required && emptyParam)
            replacement += " or 0=0 ";

        //put replacement in the query
        dataSet.queryText = dataSet.queryText.replace( placeholder, replacement );
        //DEBUG
        params["debug" + dataSet.name + "Query"]=dataSet.queryText;        
    }
}

/** Create a string list of array values,
 *  separated by separator and each of them surrounded by a pair surrounders
 */
function createList(array, separator, surrounder, sqlDataType){
    var result = "";

    for(var i=0; i<array.length; i++) {

        if(result.length>0)
            result += separator;

        if(array[i]!=null)
            result += surrounder + array[i] + surrounder;
        else
            result += "cast(null as " + sqlDataType + ")";
    }
    return result;
}

Usage example

在数据查询中,请你特别说明:

select F1, F2
from T1 
where F3= Bubi 
  and ( F4 in (  /*?customers*/) )

在<代码>前 开放式数据集与印本:

fulfillInClause(this, "(  /*?customers*/)", "customers", "string", false);

请注意,我使用一名持单人,允许在更换之前进行盘问(例如,它援引的是F4是一种var)。 You can Building a place holder thatfits.





相关问题
How do I enable caching for XML data sets in Birt 2.5

I am building a simple BIRT report using an XML data source. However, I had to use 3 different views (3 cross-tabs) of the same data on the same report. While running the report, I noticed that BIRT ...

BIRT - How to add a dynamic marker?

I have one dataset and create from this set an area chart. In this case no problem. But now I have the requirement to add dynamic markers to the chart. So, this is the example: Data Set: date | ...

在比尔特创造不均的海图间隔

我在书刊中有一个图表,大约80个数据点。 我期望将其分为三个编目:<17-20和>20。 更具体地说,Im试图制作红色黄色绿色图。

user report generation by various attributes

User table contains the following attributes (dateOfBirth, race, gender, ...). We would like to generate a report in the following format. Year Race All Male Female 2000 Asian 2000 1000 1000 ...

BIRT "Target Aggregation Name does not exist"

I m designing an accounting report with various aggregations and data fields and when I try to aggregate on a field I get the following error: "Target Aggregation Name does not exist" Now... the ...

How to do a linear regression into a BIRT report?

How to make a linear regression on the chart displayed into your BIRT report. I have x and y data... but I don t see any function on eclipse BIRT to generate the linear regression... Any idea ? Many ...