ColdFusion 9.0 Resources |
Query interfacepublic abstract interface Query Interface to a query used or created by a custom tag. A query contains tabular data organized by named columns and rows. Methods
addRowDescriptionAdds a row to a query. Call this method to append a row to a query. Returns the index of the row that was appended to the query. ExampleThe following example demonstrates the addition of two rows to a query that has three columns, City, State, and Zip: // Define column indexes int iCity = 1, iState = 2, iZip = 3 ; // First row int iRow = query.addRow() ; query.setData( iRow, iCity, "Minneapolis" ) ; query.setData( iRow, iState, "MN" ) ; query.setData( iRow, iZip, "55345" ) ; // Second row iRow = query.addRow() ; query.setData( iRow, iCity, "St. Paul" ) ; query.setData( iRow, iState, "MN" ) ; query.setData( iRow, iZip, "55105" ) ; getColumnIndexExampleThe following example retrieves the index of the EMAIL column and uses it to output a list of the addresses contained in the column: // Get the index of the EMAIL column int iEMail = query.getColumnIndex( "EMAIL" ) ; // Iterate over the query and output list of addresses int nRows = query.getRowCount() ; for( int iRow = 1; iRow <= nRows; iRow++ ) { response.write( query.getData( iRow, iEMail ) + "<BR>" ) ; } getColumnsExampleThe following example retrieves the array of columns, then iterates over the list, writing each column name back to the user: // Get the list of columns from the query String[] columns = query.getColumns() ; int nNumColumns = columns.length ; // Print the list of columns to the user response.write( "Columns in query: " ) ; for( int i=0; i<nNumColumns; i++ ) { response.write( columns[i] + " " ) ; } getDataDescriptionRetrieves a data element from a row and column of a query. Row and column indexes begin with 1. You can find the number of rows in a query by calling getRowCount. You can find the number of columns in a query by calling getColumns. Returns the value of the requested data element. Parameters
ExampleThe following example iterates over the rows of a query and writes the data back to the user in a simple, space-delimited format: int iRow, iCol ; int nNumCols = query.getColumns().length ; int nNumRows = query.getRowCount() ; for ( iRow = 1; iRow <= nNumRows; iRow++ ) { for ( iCol = 1; iCol <= nNumCols; iCol++ ) { response.write( query.getData( iRow, iCol ) + " " ) ; } response.write( "<BR>" ) ; } getRowCountsetDataDescriptionSets a data element in a row and column of a query. Row and column indexes begin with 1. Before calling setData for a given row, call addRow and use the return value as the row index for your call to setData. Parameters
ExampleThe following example demonstrates the addition of two rows to a query that has three columns, City, State, and Zip: // Define column indexes int iCity = 1, iState = 2, iZip = 3 ; // First row int iRow = query.addRow() ; query.setData( iRow, iCity, "Minneapolis" ) ; query.setData( iRow, iState, "MN" ) ; query.setData( iRow, iZip, "55345" ) ; // Second row iRow = query.addRow() ; query.setData( iRow, iCity, "St. Paul" ) ; query.setData( iRow, iState, "MN" ) ; query.setData( iRow, iZip, "55105" ) ; |