Getting column information
The DataSet object has a getColumnMetaData( ) method, which returns an IColumnMetaData object. The IColumnMetaData interface has methods that provide information about the columns in a data set, as shown in Table 37-2.
Table 37-2 Methods of the IColumnMetaData interface
Method
Returns
getColumnAlias( )
Alias of the specified column.
getColumnCount( )
Number of columns in a row of the result set.
getColumnLabel( )
Column label.
getColumnName( )
Column name at the specified index.
getColumnNativeTypeName( )
Returns the native data type. The data type is null if the column is a computed field or if the type is not known.
getColumnType( )
BIRT data type of the column at the specified index.
getColumnTypeName( )
BIRT data type name of the column at the specified index.
isComputedColumn( )
True or false, depending on whether the column is a computed field.
Get the IColumnMetaData object from the dataSet object, as shown in the following statement:
columnMetaData = this.getColumnMetaData( );
This call is not supported in the beforeOpen or the afterClose events as the instance has not been constructed or has been removed respectively at the time these two events fire. You can use the count of columns to iterate through all the columns in the data set, as shown in Listing 37‑15.
Listing 37‑15 Iterating through columns in afterOpen
importClass(org.eclipse.birt.report.engine.script.internal
.instance.DataSetInstance);
 
//Do not execute when dataset is previewed
if( this instanceof DataSetInstance ){
cmd = this.getColumnMetaData( );
colCount = cmd.getColumnCount( );
importPackage( Packages.java.io );
out = new PrintWriter( new FileWriter(
"c:/temp/columndata.txt", true ) );
for ( i = 1; i <= colCount; i++ )
{
out.println( "Column Details for Column " + i );
out.println( "Alias: " + cmd.getColumnAlias(i));
out.println( "Label: " +cmd.getColumnLabel(i));
out.println( "Name: " +cmd.getColumnName(i));
out.println( "Native Type: " + cmd.getColumnNativeTypeName(i));
out.println( "Computed?: " +cmd.isComputedColumn(i));
out.println( "Type: " +cmd.getColumnType(i));
out.println( "Type Name: " +cmd.getColumnTypeName(i));
}
out.close( );
}