Discussions
Categories
Choose a Product
THRUST SERVICES
CORE APPS
CE PRODUCTS
...
Quick Links
POPULAR
HELPFUL TIPS
Groups
My Links
FOR SIGNED IN MEMBERS:
Back to website
Home
Designing Analytics Reports
Dynamic SQL Query in scripted data set
Migrateduser
<div>Hi,</div>
<div> </div>
<div>I have some advanced requirements where I need to dynamically build SQL queries based on binding parameters. I do not have control over the BIRT (4.2.2) runtime environment, so this needs to be done using report scripting.</div>
<div> </div>
<div>I have successfully implemented a solution, based on the attached JavaScript code that is used from within scripted data sets. The scripted data sets are defined using the following pseudocode:</div>
<div>
<pre class="_prettyXprint">
open():
var dataSourceName = "MyDataSource";
var birtSqlQueryData = new BirtSqlQueryData();
var someDateParameter = this.getInputParameterValue("someDateParameter");
birtSqlQueryData.appendToQuery("select ... from ... where someColumn = ?");
birtSqlQueryData.addQueryParameter(6, new ScriptExpression("new java.util.Date("+someDateParameter +")" ));
this.birtSqlQuery = new BirtSqlQuery(dataSourceName, birtSqlQueryData);
fetch(): return this.birtSqlQuery.fetchNextRow(row);
close(): this.birtSqlQuery.close();</pre>
</div>
<div> </div>
<div>For example, I have two scripted data sets based on this approach; one named MyListData and another one MyChartData. Individually, these data sets and report elements using those data sets work as expected.</div>
<div> </div>
<div>Unfortunately, this approach doesn't work when using nested report elements. For example, when defining a List bound to MyListData, containing a Chart bound to MyChartData (with a binding parameter set to a current MyListData column value), the report fails with an exception saying 'QueryResults or its iterator has been closed'.</div>
<div> </div>
<div>Apparently closing resources for one of the data sets also closes resources for the other one. Anyone any idea why this happens?</div>
<div> </div>
<div>Thanks,</div>
<div> </div>
<div>Ruud</div>
Find more posts tagged with
Comments
There are no comments yet