The ITSet interface

The ITSet interface can be exposed by an object that contains other objects and can provide arbitrary or nonsequential access to the underlying objects.

The ITQuery::ExecToSet method provides random access to the result of a select query by returning this object. For an example of an object that exposes the ITSet interface, see the example file rowset.cpp.

Container objects that expose the ITSet interface are especially useful in GUI applications, because the random-access capabilities of the ITSet interface can be used in association with a scroll bar to support scrolling through the result set.

The following code excerpts from the rowset.cpp example illustrate the basic object container features of the row set object created by a call to ITQuery::ExecToSet:
  1. Execute a select statement and return a value object that exposes an ITSet interface.
    ITSet *set = q.ExecToSet(qtext);
    if (set == NULL)
        {
  2. Open the set.
    if (!set->Open())
        {
        }
  3. Fetch value objects from the set.
    while ((value = set->Fetch()) != NULL)
        {

    In a graphical user interface (GUI) program, the application might move to a location within the set that corresponds to the setting of a scroll bar before fetching data.

  4. Perform tasks with the value objects, releasing any interfaces when finished.
    if (value->QueryInterface(ITRowIID, (void **) &row)
        == IT_QUERYINTERFACE_FAILED)
        {
        cout << "Could not get row interface..." << endl;
        }
    else
        {
        cout << row->Printable() << endl;
        row->Release();
        }
    rowcount++;
    value->Release();
  5. Close the set.
    if (!set->Close())
        {
        }
  6. Release the set.
    set->Release();

The application can use the ITSet::Insert method to insert new members into the container objects and TSet::Delete() to remove a member.