Using Index Rowsets

Index implementations vary in their support of certain capabilities. Before an index rowset is created, consumers can determine the capabilities of the underlying index by calling IDBSchemaRowset::GetRowset for the INDEXES schema rowset. They can determine the capabilities of an index rowset to which they already have an interface pointer by calling IRowsetIndex::GetIndexInfo.

To use an index rowset, a consumer usually performs the following actions:

  1. Creates an instance of a rowset over a base table and a rowset over an index designed for use with that base table.

  2. Calls IColumnsInfo::GetColumnInfo on the index rowset to determine which column contains the bookmarks that point to rows in the base table column.

    The ordinal of this column is greater than zero and the DBCOLUMNFLAGS_ISBOOKMARK flag is set on it. GetColumnInfo also returns the key columns in the order of most significant column to least significant column. The consumer can determine which columns are the key columns by inspecting the DBINDEXCOLUMNDESC structure returned by GetIndexInfo.

  3. (Optional) Calls IRowsetIndex::SetRange on the index rowset to set the range in which to search for key values in the index. If the consumer does not call SetRange, the index rowset will search the entire index.

  4. Calls IRowsetIndex::Seek on the index rowset to set the next fetch position to a specified key value. This key value must be in the range set in step 3, which is optional.

  5. Calls IRowset::GetNextRows on the index rowset to get the row or rows from the index starting with the key value specified in step 4. GetNextRows is limited to the range set in step 3, which is optional.

  6. Calls IRowset::GetData on the index rowset for each fetched row to get the bookmarks pointing to the base table rowset.

  7. Calls IRowsetLocate::GetRowsByBookmark on the base table rowset to retrieve the rows in that rowset that correspond to the index rows fetched in step 5. this occurs only if step 3, the call to IRowsetIndex::SetRange on the index rowset, was performed.

Because an index is a rowset, the consumer can treat it like any other rowset. For example, the consumer can call methods in IRowsetChange to add, delete, and update rows in the index.