# CCFXQuery Class

Abstract class that represents a query used or created by a ColdFusion Extension (CFX). Queries contain 1 or more columns of data that extend over a varying number of rows.

## Class members

    virtual int AddRow()

CCFXQuery::AddRow adds a new row to the query.

virtual CCFXStringSet* GetColumns

CCFXQuery::GetColumns retrieves a list of the query's column names.

virtual LPCSTR GetData( int iRow, int iColumn )

CCFXQuery::GetData retrieves a data element from a row and column of the query.

virtual LPCSTR GetName()

CCFXQuery::GetName retrieves the name of the query.

virtual int GetRowCount()

CCFXQuery::GetRowCount retrieves the number of rows in the query.

virtual void SetData( int iRow, int iColumn, LPCSTR lpszData )

CCFXQuery::SetData sets a data element within a row and column of the query.

virtual void SetQueryString( LPCSTR lpszQuery )

CCFXQuery::SetQueryString sets the query string that will displayed along with query debug output.

virtual void SetTotalTime( DWORD dwMilliseconds )

CCFXQuery::SetTotalTime sets the total time that was required to process the query (used for debug output).

## CCFXQuery::AddRow

    int CCFXQuery::AddRow(void)

Add a new row to the query. You should call this function each time you want to append a row to the query.

Returns the index of the row that was appended to the query.

#### Example

The following example demonstrates the addition of 2 rows to a query that has 3 columns ('City', 'State', and 'Zip'):

    // 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" ) ;

## CCFXQuery::GetColumns

    CCFXStringSet* CCFXQuery::GetColumns(void)

Retrieves a list of the column names contained in the query.

Returns an object of CCFXStringSet Class that contains a list of the columns contained in the query. You are not responsible for freeing the memory allocated for the returned string set (it will be freed automatically by ColdFusion after the request is completed).

#### Example

The following example retrieves the list of columns and 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( " " ) ;
    }

## CCFXQuery::GetData

    LPCSTR CCFXQuery::GetData(int iRow, int iColumn)

Retrieves a data element from a row and column of the query. Row and column indexes begin with 1. You can determine the number of rows in the query by calling CCFXQuery::GetRowCount. You can determine the number of columns in the 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.

    iRow

Row to retrieve data from (1-based).

lColumn

Column to retrieve data from (1-based).

#### Example

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>" ) ;
    }

## CCFXQuery::GetName

    LPCSTR CCFXQuery::GetName(void)

Retrieves the name of the query. Returns the name of the query.

#### Example

The following example retrieves the name of the query and writes it back to the user:

    CCFXQuery* pQuery = pRequest->GetQuery() ;
    pRequest->Write( "The query name is: " ) ;
    pRequest->Write( pQuery->GetName() ) ;

## CCFXQuery::GetRowCount

    LPCSTR CCFXQuery::GetRowCount(void)

Retrieves the number of rows in the query. Returns the number of rows contained in the query.

#### Example

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 ) ;

## CCFXQuery::SetData

    void CCFXQuery::SetData(int iRow, int iColumn, LPCSTR lpszData)

Sets a data element within a row and column of the query. Row and column indexes begin with 1. Before calling `SetData` for a given row, you should be sure to call CCFXQuery::AddRow and use the return value as the row index for your call to `SetData`.

    iRow

Row of data element to set (1-based).

lColumn

Column of data element to set (1-based).

lpszData

New value for data element.

#### Example

The following example demonstrates the addition of 2 rows to a query that has 3 columns ('City', 'State', and 'Zip'):

    // 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" ) ;

## CCFXQuery::SetQueryString

This is a deprecated function and should not be used.

## CCFXQuery::SetTotalTime

This is a deprecated function and should not be used.