The following describes scrollable cursors for the ASE OLE DB Provider.
The OLE DB Data Provider supports the following scrolling types:
Next – return the next row.
Prior – return the prior row.
Relative n rows – return the row, n rows from the current rowset.
You must set the following attributes to use scrollable cursors:
DBPROP_CANSCROLLBACKWARDS – if set to VARIANT_TRUE, the rowset allows the lRowsOffset parameter of GetNextRows to be negative.
DBPROP_CANFETCHBACKWARDS – if set to VARIANT_TRUE, the rowset will allow the cRows parameter of GetNextRows to be negative.
To set up a program to execute a scrollable cursor
Set the scrollable cursor properties on the rowset:
DBPROP RowsetProperties[2]; for(int i = 0; i < 2; i++) VariantInit(&RowsetProperties[i].vValue); RowsetProperties[0].dwPropertyID = DBPROP_CANFETCHBACKWARDS; RowsetProperties[0].vValue.vt = VT_BOOL; RowsetProperties[0].vValue.boolVal= VARIANT_TRUE; RowsetProperties[0].dwOptions = DBPROPOPTIONS_REQUIRED; RowsetProperties[0].colid = DB_NULLID; RowsetProperties[1].dwPropertyID = DBPROP_CANSCROLLBACKWARDS; RowsetProperties[1].vValue.vt = VT_BOOL; RowsetProperties[1].vValue.boolVal= VARIANT_TRUE; RowsetProperties[1].dwOptions = DBPROPOPTIONS_REQUIRED; RowsetProperties[1].colid = DB_NULLID;DBPROPSET rgRowsetPropSet[1]; rgRowsetPropSet[0].guidPropertySet = DBPROPSET_ROWSET; rgRowsetPropSet[0].cProperties = 2; rgRowsetPropSet[0].rgProperties = RowsetProperties;
Open the rowset:
IRowset* pIRowset = ds.OpenRowset("book", 1, rgRowsetPropSet);
Fetch the rows forward:
DBCOUNTITEM cRowsReturned; HROW hRow[3]; HROW* pRows = hRow; hr = pIRowset->GetNextRows(NULL, 0, 3, &cRowsReturned, &pRows);
Release the rows:
hr = pIRowset->ReleaseRows(cRowsReturned, pRows, NULL, NULL, NULL);
Fetch the rows backward:
DBCOUNTITEM cRowsReturned; HROW hRow[3]; HROW* pRows = hRow; hr = pIRowset->GetNextRows(NULL, 0, -3, &cRowsReturned, &pRows);
Release the rows:
hr = pIRowset->ReleaseRows(cRowsReturned, pRows, NULL, NULL, NULL);
Release the rowset:
pIRowset->Release()
To identify the results and the result set interpretation, after you execute a scrollable cursor, refer to the Microsoft MSDN library.
For an example of a scrollable, static-insensitive cursor program refer to the previous section.