An abstract class that represents a query used or created by a ColdFusion Extension (CFX). Queries contain one or more columns of data that extend over a varying number of rows.
virtual int AddRow() |
CCFXQuery::AddRow adds a row to a query. |
virtual int AddRow() virtual CCFXStringSet* GetColumns |
CCFXQuery::GetColumns retrieves a list of a query's column names. |
virtual LPCSTR GetData( int iRow, int iColumn ) |
CCFXQuery::GetData retrieves a data element from a row and column of a query. |
virtual LPCSTR GetName() |
CCFXQuery::GetName retrieves the name of a query. |
virtual int GetRowCount() |
CCFXQuery::GetRowCount retrieves the number of rows in a query. |
virtual void SetData( int iRow, int iColumn, LPCSTR lpszData ) |
CCFXQuery::SetData sets a data element within a row and column of a query. |
virtual void SetQueryString( LPCSTR lpszQuery ) |
This function is deprecated. Do not use it in new applications. It might not work, and might cause an error, in later releases. |
virtual void SetTotalTime( DWORD dwMilliseconds ) |
This function is deprecated. Do not use it in new applications. It might not work, and might cause an error, in later releases. |
int CCFXQuery::AddRow(void)
Add a row to the query. Call this function to append a row to a query.
Returns the index of the row that was appended to a query.
The following example shows the addition of two rows to a three-column ('City', 'State', and 'Zip') query:
// First row int iRow ; iRow = pQuery->AddRow() ; pQuery->SetData( iRow, iCity, "Minneapolis" ) ; pQuery->SetData( iRow, iState, "MN" ) ; pQuery->SetData( iRow, iZip, "55345" ) ; // Second row iRow = pQuery->AddRow() ; pQuery->SetData( iRow, iCity, "St. Paul" ) ; pQuery->SetData( iRow, iState, "MN" ) ; pQuery->SetData( iRow, iZip, "55105" ) ;
CCFXStringSet* CCFXQuery::GetColumns(void)
Retrieves a list of the column names contained in a query.
Returns an object of CCFXStringSet Class that contains a list of the columns in the query. ColdFusion automatically frees the memory that is allocated for the returned string set, after the request is completed.
The following example gets the list of columns, then iterates over the list, writing each column name back to the user:
// Get the list of columns from the query CCFXStringSet* pColumns = pQuery->GetColumns() ; int nNumColumns = pColumns->GetCount() ; // Print the list of columns to the user pRequest->Write( "Columns in query: " ) ; for( int i=1; i<=nNumColumns; i++ ) { pRequest->Write( pColumns->GetString( i ) ) ; pRequest->Write( " " ) ; }
LPCSTR CCFXQuery::GetData(int iRow, int iColumn)
Gets a data element from a row and column of a query. Row and column indexes begin with 1. You can determine the number of rows in a query by calling CCFXQuery::GetRowCount. You can determine the number of columns in a query by retrieving the list of columns using CCFXQuery::GetColumns, and then calling CCFXStringSet::GetCount on the returned string set.
Returns the value of the requested data element.
Parameter | Description |
---|---|
iRow |
Row to retrieve data from (1-based) |
iColumn |
Column to retrieve data from (1-based) |
The following example iterates over the elements of a query and writes the data in the query back to the user in a simple, space-delimited format:
int iRow, iCol ; int nNumCols = pQuery->GetColumns()->GetCount() ; int nNumRows = pQuery->GetRowCount() ; for ( iRow=1; iRow<=nNumRows; iRow++ ) { for ( iCol=1; iCol<=nNumCols; iCol++ ) { pRequest->Write( pQuery->GetData( iRow, iCol ) ) ; pRequest->Write( " " ) ; } pRequest->Write( "<BR>" ) ; }
LPCSTR CCFXQuery::GetName(void)
The following example retrieves the name of a query and writes it back to the user:
CCFXQuery* pQuery = pRequest->GetQuery() ; pRequest->Write( "The query name is: " ) ; pRequest->Write( pQuery->GetName() ) ;
LPCSTR CCFXQuery::GetRowCount(void)
Returns the number of rows contained in a query.
The following example retrieves the number of rows in a query and writes it back to the user:
CCFXQuery* pQuery = pRequest->GetQuery() ; char buffOutput[256] ; wsprintf( buffOutput, "The number of rows in the query is %ld.", pQuery->GetRowCount() ) ; pRequest->Write( buffOutput ) ;
void CCFXQuery::SetData(int iRow, int iColumn, LPCSTR lpszData)
Sets a data element within a row and column of a query. Row and column indexes begin with 1. Before calling SetData
for a given row, call CCFXQuery::AddRow and use the return value as the row index for your call to SetData
.
Parameter | Description |
---|---|
iRow |
Row of data element to set (1-based) |
iColumn |
Column of data element to set (1-based) |
lpszData |
New value for data element |
The following example shows the addition of two rows to a three-column ('City', 'State', and 'Zip') query:
// First row int iRow ; iRow = pQuery->AddRow() ; pQuery->SetData( iCity, iRow, "Minneapolis" ) ; pQuery->SetData( iState, iRow, "MN" ) ; pQuery->SetData( iZip, iRow, "55345" ) ; // Second row iRow = pQuery->AddRow() ; pQuery->SetData( iCity, iRow, "St. Paul" ) ; pQuery->SetData( iState, iRow, "MN" ) ; pQuery->SetData( iZip, iRow, "55105" ) ;