Getting the Query Results for Display

Note

Indexing Service is no longer supported as of Windows XP and is unavailable for use as of Windows 8. Instead, use Windows Search for client side search and Microsoft Search Server Express for server side search.

 

The following code segments from the IssueQuery function of the sample get the results of the query for subsequent display. The function first declares an IAccessor interface and uses the QueryInterface method of the IRowset interface to get a pointer to an IAccessor interface for the query's rowset.

...
    XInterface<IAccessor> xIAccessor;
    hr = xIRowset->QueryInterface( IID_IAccessor,
                                   xIAccessor.GetQIPointer() );
...

After determining the number of columns in the result and binding each column with the appropriate buffer information, the function declares a handle to an accessor and uses the CreateAccessor method of the IAccessor interface to create the accessor from the bindings.

...
    HACCESSOR hAccessor;
    hr = xIAccessor->CreateAccessor( DBACCESSOR_ROWDATA, // rowdata accessor
                                     cColumns,           // # of columns
                                     xBindings.Get(),    // columns
                                     0,                  // ignored
                                     &amp;hAccessor,         // result
                                     0 );                // no status
...

The function finally uses the GetData method of the IRowset interface to get the data for subsequent display.

...
            for ( DBCOUNTITEM iRow = 0; iRow < cRowsReturned; iRow++ )
            {
                HRESULT hr2 = xIRowset->GetData( aHRow[iRow],   // hrow being accessed
                                                 hAccessor,     // accessor to use
                                                 xData.Get() ); // resulting data
...
            }
...