How to retrieve ResultSet metadata in script [message #684858] |
Thu, 16 June 2011 11:03 |
Andreas G 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);
}
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03492 seconds