Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » How to pass a multi-value parameter to a database/DataSet
How to pass a multi-value parameter to a database/DataSet [message #364965] Wed, 03 September 2008 10:23 Go to next message
Lukas Svoboda is currently offline Lukas Svoboda
Messages: 2
Registered: July 2009
Junior Member
Hi,
one of my input parameter in data set needs to be a set -- a set of
Strings. I know how to make a multi-value parameter, but I don't know how
to paste it to the database.

I'd like to join the input values (separated by ;) into one string and
paste it to the store procedure to returns my data.
I think one way could be fill this parameter in before factory script:

importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.ele ments);

dshandle =
reportContext.getReportRunnable().designHandle.getDesignHand le().findDataSet( "testDataSet");
//org.eclipse.birt.report.model.api DataSetHandle
par = dshandle.paramBindingsIterator();

while( par.hasNext() ){
parHandle = par.next();
parHandle.setExpression("Test to set all params");
if( parHandle.getParamName() == "param_6"){
parHandle.set("Test to set the right param");
}
}

but it doesn't set any param.

I welcome any ideas about why the code above does not work or how else
could I achieve my goal -- the goal of passing multiple-value parameter (a
set) to the database (stored procedure).

Thanks,
Lukas
Re: How to pass a multi-value parameter to a database/DataSet [message #364966 is a reply to message #364965] Wed, 03 September 2008 11:58 Go to previous messageGo to next message
Eclipse User
Originally posted by: jasonweathersby.alltel.net

Lukas,

Take a look at the attached example. It does not use dataset parameters
but does use report parameters from a multiselect parameter. Look at
the script on the orderdetails dataset and see how the query is changed
using the report parameter.

Jason


<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.16"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.3.0.v20080606 Build &lt;2.3.0.v20080618-0630></property>
<property name="units">in</property>
<property name="comments">Copyright (c) 2007 &lt;&lt;Your Company
Name here>></property>
<html-property name="description">Creates a blank report with no
predefined content.</html-property>
<text-property name="displayName">Blank Report</text-property>
<property name="iconFile">/templates/blank_report.gif</property>
<parameters>
<scalar-parameter name="parmorders" id="8">
<property name="valueType">dynamic</property>
<property name="dataType">string</property>
<property name="paramType">multi-value</property>
<property name="controlType">list-box</property>
<property name="dataSetName">parmDataSet</property>
<expression
name="valueExpr">dataSetRow["CUSTOMERNUMBER"]</expression >
<property name="mustMatch">true</property>
<property name="fixedOrder">true</property>
<property name="distinct">true</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
</parameters>
<data-sources>
<oda-data-source
extensionID="org.eclipse.birt.report.data.oda.jdbc" name="Data Source"
id="6">
<property
name="odaDriverClass">org.eclipse.birt.report.data.oda.sampledb.Driver </property>
<property name="odaURL">jdbc:classicmodels:sampledb</property>
<property name="odaUser">ClassicModels</property>
</oda-data-source>
</data-sources>
<data-sets>
<oda-data-set
extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet "
name="parmDataSet" id="7">
<list-property name="columnHints">
<structure>
<property name="columnName">CUSTOMERNUMBER</property>
<property name="displayName">CUSTOMERNUMBER</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">CUSTOMERNUMBER</property>
<property name="dataType">integer</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">CUSTOMERNUMBER</property>
<property name="nativeName">CUSTOMERNUMBER</property>
<property name="dataType">integer</property>
<property name="nativeDataType">4</property>
</structure>
</list-property>
<property name="queryText">select customernumber
from orders</property>
</oda-data-set>
<oda-data-set
extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet "
name="orderdetails" id="10">
<list-property name="columnHints">
<structure>
<property name="columnName">ORDERNUMBER</property>
<property name="displayName">ORDERNUMBER</property>
</structure>
<structure>
<property name="columnName">ORDERDATE</property>
<property name="displayName">ORDERDATE</property>
</structure>
<structure>
<property name="columnName">REQUIREDDATE</property>
<property name="displayName">REQUIREDDATE</property>
</structure>
<structure>
<property name="columnName">SHIPPEDDATE</property>
<property name="displayName">SHIPPEDDATE</property>
</structure>
<structure>
<property name="columnName">STATUS</property>
<property name="displayName">STATUS</property>
</structure>
<structure>
<property name="columnName">COMMENTS</property>
<property name="displayName">COMMENTS</property>
</structure>
<structure>
<property name="columnName">CUSTOMERNUMBER</property>
<property name="displayName">CUSTOMERNUMBER</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">ORDERNUMBER</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">ORDERDATE</property>
<property name="dataType">date</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">REQUIREDDATE</property>
<property name="dataType">date</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">SHIPPEDDATE</property>
<property name="dataType">date</property>
</structure>
<structure>
<property name="position">5</property>
<property name="name">STATUS</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">6</property>
<property name="name">COMMENTS</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">7</property>
<property name="name">CUSTOMERNUMBER</property>
<property name="dataType">integer</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<method name="beforeOpen"><![CDATA[var parmcount =
params["parmorders"].value.length
var whereclause = "";
if( parmcount > 0 ){
whereclause = " where customernumber in ( ";
}
for( i=0; i < parmcount; i++ ){
if( i == 0 ){
whereclause = whereclause + params["parmorders"].value[i];
}else{
whereclause = whereclause + " , " + params["parmorders"].value[i];
}
}
if( parmcount > 0 ){
this.queryText = this.queryText + whereclause + " ) ";
}]]></method>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">ORDERNUMBER</property>
<property name="nativeName">ORDERNUMBER</property>
<property name="dataType">integer</property>
<property name="nativeDataType">4</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">ORDERDATE</property>
<property name="nativeName">ORDERDATE</property>
<property name="dataType">date</property>
<property name="nativeDataType">91</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">REQUIREDDATE</property>
<property name="nativeName">REQUIREDDATE</property>
<property name="dataType">date</property>
<property name="nativeDataType">91</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">SHIPPEDDATE</property>
<property name="nativeName">SHIPPEDDATE</property>
<property name="dataType">date</property>
<property name="nativeDataType">91</property>
</structure>
<structure>
<property name="position">5</property>
<property name="name">STATUS</property>
<property name="nativeName">STATUS</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
<structure>
<property name="position">6</property>
<property name="name">COMMENTS</property>
<property name="nativeName">COMMENTS</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
<structure>
<property name="position">7</property>
<property name="name">CUSTOMERNUMBER</property>
<property name="nativeName">CUSTOMERNUMBER</property>
<property name="dataType">integer</property>
<property name="nativeDataType">4</property>
</structure>
</list-property>
<property name="queryText">select *
from orders</property>
</oda-data-set>
</data-sets>
<styles>
<style name="crosstab" id="4">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab-cell" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="detail" id="45">
<property name="backgroundColor">#BACAE2</property>
<property name="fontFamily">"Arial"</property>
<property name="fontSize">small</property>
<property name="paddingTop">0px</property>
<property name="paddingLeft">0px</property>
<property name="paddingBottom">0px</property>
<property name="paddingRight">0px</property>
</style>
<style name="headerfooter" id="46">
<property name="backgroundColor">#004080</property>
<property name="fontFamily">"Arial"</property>
<property name="fontSize">small</property>
<property name="fontWeight">bold</property>
<property name="color">#FFFFFF</property>
</style>
<style name="groupheader" id="47">
<property name="backgroundColor">#0080FF</property>
<property name="fontFamily">"Arial"</property>
<property name="fontSize">small</property>
<property name="fontWeight">bold</property>
<property name="color">#FFFFFF</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property
name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<table id="97">
<property name="width">100%</property>
<property name="dataSet">orderdetails</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">ORDERNUMBER</property>
<expression
name="expression">dataSetRow["ORDERNUMBER"]</expression >
<property name="dataType">integer</property>
</structure>
<structure>
<property name="name">ORDERDATE</property>
<expression
name="expression">dataSetRow["ORDERDATE"]</expression>
<property name="dataType">date</property>
</structure>
<structure>
<property name="name">REQUIREDDATE</property>
<expression
name="expression">dataSetRow["REQUIREDDATE"]</expression >
<property name="dataType">date</property>
</structure>
<structure>
<property name="name">SHIPPEDDATE</property>
<expression
name="expression">dataSetRow["SHIPPEDDATE"]</expression >
<property name="dataType">date</property>
</structure>
<structure>
<property name="name">STATUS</property>
<expression
name="expression">dataSetRow["STATUS"]</expression>
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">COMMENTS</property>
<expression
name="expression">dataSetRow["COMMENTS"]</expression>
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">CUSTOMERNUMBER</property>
<expression
name="expression">dataSetRow["CUSTOMERNUMBER"]</expression >
<property name="dataType">integer</property>
</structure>
</list-property>
<property name="pageBreakInterval">50</property>
<column id="136"/>
<column id="137"/>
<column id="140"/>
<header>
<row id="98">
<property name="style">headerfooter</property>
<cell id="99">
<label id="100">
<text-property
name="text">ORDERNUMBER</text-property>
</label>
</cell>
<cell id="101">
<label id="102">
<text-property
name="text">ORDERDATE</text-property>
</label>
</cell>
<cell id="107">
<label id="108">
<text-property
name="text">STATUS</text-property>
</label>
</cell>
</row>
</header>
<group id="143">
<property name="groupName">NewTableGroup1</property>
<property name="interval">none</property>
<property name="sortDirection">asc</property>
<expression
name="keyExpr">row["CUSTOMERNUMBER"]</expression>
<structure name="toc">
<expression
name="expressionValue">row["CUSTOMERNUMBER"]</expression >
</structure>
<property name="repeatHeader">true</property>
<property name="hideDetail">false</property>
<property name="pageBreakAfter">auto</property>
<property name="pageBreakBefore">auto</property>
<property name="pageBreakInside">auto</property>
<header>
<row id="144">
<property name="style">groupheader</property>
<cell id="145">
<data id="154">
<property
name="resultSetColumn">CUSTOMERNUMBER</property>
</data>
</cell>
<cell id="146"/>
<cell id="147"/>
</row>
</header>
</group>
<detail>
<row id="113">
<property name="style">detail</property>
<cell id="114">
<data id="115">
<property
name="resultSetColumn">ORDERNUMBER</property>
</data>
</cell>
<cell id="116">
<data id="117">
<property
name="resultSetColumn">ORDERDATE</property>
</data>
</cell>
<cell id="122">
<data id="123">
<property
name="resultSetColumn">STATUS</property>
</data>
</cell>
</row>
</detail>
</table>
</body>
</report>


Lukas Svoboda wrote:
> Hi,
> one of my input parameter in data set needs to be a set -- a set of
> Strings. I know how to make a multi-value parameter, but I don't know
> how to paste it to the database.
>
> I'd like to join the input values (separated by ;) into one string and
> paste it to the store procedure to returns my data.
> I think one way could be fill this parameter in before factory script:
>
> importPackage(Packages.org.eclipse.birt.report.model.api);
> importPackage(Packages.org.eclipse.birt.report.model.api.ele ments);
>
> dshandle =
> reportContext.getReportRunnable().designHandle.getDesignHand le().findDataSet( "testDataSet");
>
> //org.eclipse.birt.report.model.api DataSetHandle
> par = dshandle.paramBindingsIterator();
>
> while( par.hasNext() ){
> parHandle = par.next();
> parHandle.setExpression("Test to set all params");
> if( parHandle.getParamName() == "param_6"){
> parHandle.set("Test to set the right param");
> }
> }
>
> but it doesn't set any param.
>
> I welcome any ideas about why the code above does not work or how else
> could I achieve my goal -- the goal of passing multiple-value parameter
> (a set) to the database (stored procedure).
>
> Thanks,
> Lukas
>
Re: How to pass a multi-value parameter to a database/DataSet [message #365008 is a reply to message #364966] Fri, 05 September 2008 04:09 Go to previous message
Lukas Svoboda is currently offline Lukas Svoboda
Messages: 2
Registered: July 2009
Junior Member
Thanks Janson,

in the and I found a lot of similar solutions, eg:
http://www.birt-exchange.com/forum/designing-birt-reports/92 24-passing-dynamic-multiple-values-report-parameter-birt.htm l
http://download.eclipse.org/birt/downloads/examples/reports/ 2.1/querymod/querymod.html

but all of them don't escape parameters passing to the SQL query.
Finally I designed DataSet this way:
* set 'Query' as:
select * from repo.sumarizace_neefektivni_apl_tab(?,?,?,?,?,?,?,?,?)
* setup all params in the 'Parameters' tab. The one, that is a multi
value I set to type String, and to the 'Default value' tab I wrote this
code:
function formatListQueryParams(paramsArray) {
var queryStr="";
for (var index = 0; index < paramsArray.length; index++) {
queryStr = queryStr.concat(paramsArray[index] + ";");
}
queryStr = queryStr.substr(0, queryStr.length - 1);
return queryStr;
}
formatListQueryParams(reportContext.getParameterValue("app_names "));

* the others params I setup as a 'Linked To Report Parameter'

and on the Postges side I used the parameter this way:
b.apl_name NOT IN (select regexp_split_to_table($6,E';'))

Lukas
Previous Topic:Client-side javascript not work on IE 6.0
Next Topic:An unwated Horizontal Sroll bar is being displayed in IE7
Goto Forum:
  


Current Time: Wed Apr 16 18:57:35 EDT 2014

Powered by FUDForum. Page generated in 0.03709 seconds