Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » How to retrieve ResultSet metadata in script(How to retrieve ResultSet metadata in script for a dynamic from-clause)
icon9.gif  How to retrieve ResultSet metadata in script [message #684858] Thu, 16 June 2011 11:03 Go to next message
Andreas G is currently offline Andreas GFriend
Messages: 5
Registered: June 2011
Junior Member
Hi,

I have a problem concerning a scripted table within a report.

I made a script (in the report's initialize method) that you will find attached at the very end of this topic. The script is called in the beforeRender method of the Report.

The script generates a table depending on the structure of the ResultSet (e.g. adding columns, labels and expressions per ResultSet column). As I want to decide at runtime what table I want to read, I cannot use "iterator = dataset.resultSetIterator();" what is the actual base of my whole script but has to be replaced.
Before executing the query I neither know the number of columns in the ResultSet nor their names.
At the moment the script just brings a listing of any query in the dataset - changes will be applied when this part works.

Everything works fine when I have the <list-property name="resultSet">-Tag in my source what I'm not able to have as the table structure is unknown before runtime.

I tried to create a DataSet and execute the query on my own like described in www.eclipse.org/forums/index.php/m/669570, what did not work for some reason (spent a day always getting an empty result set).

I searched many forums and google but couldn't find a trick to get the metadata. So I'm here. I hope that you can help me. Pleeeease ;)

Adios,

Andreas

PS: Doing all that with column bindings and expressions would be nice, but I won't mind parsing the ResultSet by myself either.


importPackage( Packages.org.eclipse.birt.report.model.api );
function createTable() {
if(reportContext.getReportRunnable().designHandle.getModuleHandle().findElement("dynamicTable")) {
reportContext.getReportRunnable().designHandle.getBody().drop(reportContext.getReportRunnable().designHandle.getModuleHandle().findElement("dynamicTable"));
}

elementFactory = reportContext.getDesignHandle().getElementFactory();

dataset = reportContext.getReportRunnable().designHandle.getModuleHandle().findDataSet("Data Set");

dynamicTable = elementFactory.newTableItem("dynamicTable", 0);
dynamicTable.setDataSet(dataset);
dynamicTable.setProperty("style", "table");
dynamicTable.setProperty("marginBottom", "1cm");

columnBindings = dynamicTable.getColumnBindings( );

iterator = dataset.resultSetIterator(); //PROBLEM
dataSetColumn = 0;


while(iterator.hasNext()) {
actual = iterator.next();

dynamicTable.insertColumn(dataSetColumn+1,1);

columnHandle = dynamicTable.getColumns().get(dataSetColumn);
columnHandle.setProperty("width", "100px");
columnHandle.setProperty("textAlign", "center");

computedColumn = StructureFactory.createComputedColumn();
computedColumn.setName(actual.getColumnName());

bindingName = actual.getColumnName();


computedColumn.setExpression("dataSetRow[\"" + bindingName + "\"]");
columnBindings.addItem(computedColumn);

header = dynamicTable.getHeader().get(0);
header.setProperty("style", "tableHeader");
headerCell = header.getCells().get(dataSetColumn);
newLabel = elementFactory.newLabel(bindingName + "Label");
newLabel.setText(bindingName);
headerCell.getContent().add(newLabel);

detail = dynamicTable.getDetail().get(0);
detailCell = detail.getCells().get(dataSetColumn);
detailCell.setProperty("style", "tableCell");
newData = elementFactory.newDataItem(null);
newData.setResultSetColumn(actual.getColumnName());
detailCell.getContent().add(newData);

dataSetColumn++;

}


reportContext.getReportRunnable().designHandle.getBody().add(dynamicTable,0);
}
Re: How to retrieve ResultSet metadata in script [message #684939 is a reply to message #684858] Thu, 16 June 2011 13:54 Go to previous messageGo to next message
Andreas G is currently offline Andreas GFriend
Messages: 5
Registered: June 2011
Junior Member
Hum.

The link is
www.eclipse.org/forums/index.php/m/669570/ and not
www.eclipse.org/forums/index.php/m/669570

Oo weird, isn't it? =)
Re: How to retrieve ResultSet metadata in script [message #684955 is a reply to message #684939] Thu, 16 June 2011 14:24 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Look at the attached example for calling the dataengine. Notice it is called in the beforeFactory which is the last place you can add items to the report design (beforeRender) is to late.

Jason
Re: How to retrieve ResultSet metadata in script [message #684969 is a reply to message #684955] Thu, 16 June 2011 14:32 Go to previous messageGo to next message
Andreas G is currently offline Andreas GFriend
Messages: 5
Registered: June 2011
Junior Member
Thanks for the quick reply. I'll check!
Re: How to retrieve ResultSet metadata in script [message #685008 is a reply to message #684969] Thu, 16 June 2011 15:54 Go to previous message
Andreas G is currently offline Andreas GFriend
Messages: 5
Registered: June 2011
Junior Member
Woooohooooo! It works! Thank you, Jason!
*bows*
Previous Topic:Tooltips on simple labels?
Next Topic:dynamic data set from different table different feilds, according to parameter
Goto Forum:
  


Current Time: Fri Apr 19 22:14:14 GMT 2024

Powered by FUDForum. Page generated in 0.03113 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top