Allows direct positioning at a key value within the current range established by the IRowsetIndex::SetRange method.
HRESULT Seek ( HACCESSOR hAccessor, DBORDINAL cKeyValues, void *pData, DBSEEK dwSeekOptions);
Parameters
If the accessor does not meet these criteria, the method returns DB_E_BADBINDINFO or a status of DBSTATUS_E_BADACCESSOR for the offending column.
If hAccessor is the handle of a null accessor (cBindings in IAccessor::CreateAccessor was zero), IRowsetIndex::Seek does not change the next fetch position.
Value | Description |
---|---|
DBSEEK_FIRSTEQ | First key with values equal to the values in *pData, in index order. |
DBSEEK_LASTEQ | Last key with values equal to the values in *pData. |
DBSEEK_AFTEREQ | Last key with values equal to the values in *pData or, if there are no keys equal to the values in *pData, first key with values after the values in *pData, in index order. |
DBSEEK_AFTER | First key with values following the values in *pData, in index order. |
DBSEEK_BEFOREEQ | First key with values equal to the values in *pData or, if there are no keys equal to the values in *pData, last key with values before the values in *pData, in index order. |
DBSEEK_BEFORE | Last key with values before the values in *pData, in index order. |
dwSeekOptions examples
The following table shows the expected results when given the columns and index value for the DBSEEK predicates above.
Col 1 | Col 2 | Col 3 | With index setting of | Predicate | Result |
---|---|---|---|---|---|
0 1 2 3 |
index = col1 asc | BEFORE (2)
BEFOREEQ (2) |
(1)
(2) |
||
1 2 2 3 |
1 2 3 4 |
index = (col1 asc) | BEFOREEQ (2)
AFTEREQ (2) |
(2,2)
(2,3) |
|
1 3 3 4 |
4 3 3 1 |
0 1 2 3 |
index = (col1 asc, col2 desc) | BEFOREEQ (3,3)
AFTEREQ (3,3) |
(3,3,1)
(3,3,2) |
Return Code
hAccessor was the handle of a null accessor.
cKeyValues was zero or was greater than the number of bindings specified in hAccessor.
pData was a null pointer.
Comments
If this method performs deferred accessor validation and that validation takes place before any data is transferred, it can also return any of the following return codes for the reasons listed in the corresponding DBBINDSTATUS values in IAccessor::CreateAccessor:
E_NOINTERFACE
DB_E_BADBINDINFO
DB_E_BADORDINAL
DB_E_BADSTORAGEFLAGS
DB_E_UNSUPPORTEDCONVERSION
The IRowsetIndex::Seek method provides the caller more control over the traversal of an index. Consider a relational query processor component implementing a merge join over inputs R1 and R2. R1, the outer input, is a rowset ordered by the joining column R1.X. R2, the inner input, is an indexed rowset on column R2.X. Suppose that R1.X has values {10, 20, 100, 110} and that R2.X has values {10, 20, ..., 30, ..., 40, ..., 50, ..., 100, ...}; then when searching R2.X, one could seek directly from 20 to 100 knowing the values of the input R1.X. In some cases, this strategy could be cost effective.
For information about how IRowsetIndex::Seek transfers data from *pData, see "Setting Data" in Chapter 6: Getting and Setting Data.
IRowset::GetNextRows | IRowsetIndex::SetRange