SQLOLEDB exposes SQL Server cursors through rowsets, allowing developers to use SQL Server concurrency control mechanisms. SQLOLEDB creates SQL Server cursors that support rowsets when the rowset properties indicate that the consumer:
Specific rowset properties required by the consumer direct SQLOLEDB use of SQL Server cursors. If the consumer sets no rowset properties, or sets all rowset properties to their default values, SQLOLEDB does not create a SQL Server cursor to support the rowset.
The following rowset properties direct SQLOLEDB use of SQL Server cursors. Some properties can be safely combined with others. For example, a rowset that exhibits the DBPROP_IRowsetScroll and DBPROP_IRowsetChange properties will be a bookmark rowset exhibiting immediate update behavior. Other properties are mutually exclusive. For example, a rowset exhibiting DBPROP_OTHERINSERT cannot contain bookmarks.
Property ID | Rowset behavior |
DBPROP_SERVERCURSOR | VARIANT_TRUE Cannot update SQL Server data through the rowset. The rowset is sequential, supporting forward scrolling and fetching only. Relative row positioning is supported. Command text can contain an ORDER BY clause. |
DBPROP_ CANSCROLLBACKWARDS or DBPROP_ CANFETCHBACKWARDS |
VARIANT_TRUE Cannot update SQL Server data through the rowset. The rowset supports scrolling and fetching in either direction. Relative row positioning is supported. Command text can contain an ORDER BY clause. |
DBPROP_BOOKMARKS or DBPROP_LITERALBOOKMARKS | VARIANT_TRUE Cannot update SQL Server data through the rowset. The rowset is sequential, supporting forward scrolling and fetching only. Relative row positioning is supported. Command text can contain an ORDER BY clause. |
DBPROP_OWNUPDATEDELETE or DBPROP_OWNINSERT or DBPROP_OTHERUPDATEDELETE | VARIANT_TRUE Cannot update SQL Server data through the rowset. The rowset supports scrolling and fetching in either direction. Relative row positioning is supported. Command text can contain an ORDER BY clause. |
DBPROP_OTHERINSERT | VARIANT_TRUE Cannot update SQL Server data through the rowset. The rowset supports scrolling and fetching in either direction. Relative row positioning is supported. Command text cannot contain an ORDER BY clause. DBPROP_OTHERINSERT cannot be VARIANT_TRUE if the rowset contains bookmarks. Attempting to create a rowset with this visibility property and bookmarks results in an error. |
DBPROP_IRowsetLocate or DBPROP_IRowsetScroll | VARIANT_TRUE Cannot update SQL Server data through the rowset. The rowset supports scrolling and fetching in either direction. Bookmarks and absolute positioning through IRowsetLocate are supported in the rowset. Command text can contain an ORDER BY clause. DBPROP_IRowsetLocate and DBPROP_ IRowsetScroll require bookmarks in the rowset. Attempting to create a rowset with bookmarks and DBPROP_OTHERINSERT set to VARIANT_TRUE results in an error. |
DBPROP_IRowsetChange or DBPROP_IRowsetUpdate | VARIANT_TRUE Can update SQL Server data through the rowset. The rowset is sequential, supporting forward scrolling and fetching only. Relative row positioning is supported. Command text cannot contain an ORDER BY clause. |
DBPROP_IRowsetLocate or DBPROP_IRowsetScroll and DBPROP_IRowsetChange or DBPROP_IRowsetUpdate | VARIANT_TRUE Can update SQL Server data through the rowset. The rowset supports scrolling and fetching in either direction. Bookmarks and absolute positioning through IRowsetLocate are supported in the rowset. Command text can contain an ORDER BY clause. |
DBPROP_IMMOBILEROWS | VARIANT_FALSE Cannot update SQL Server data through the rowset. The rowset supports forward scrolling only. Relative row positioning is supported. Command text cannot contain an ORDER BY clause. DBPROP_IMMOBILEROWS is only available in rowsets that can show SQL Server rows inserted by commands on other sessions or by other users. Attempting to open a rowset with the property set to VARIANT_FALSE on any rowset for which DBPROP_OTHERINSERT cannot be VARIANT_TRUE results in an error. |
DBPROP_REMOVEDELETED | VARIANT_TRUE Cannot update SQL Server data through the rowset. The rowset supports forward scrolling only. Relative row positioning is supported. Command text can contain an ORDER BY clause unless constrained by another property. |
A SQLOLEDB rowset supported by a SQL Server cursor can be easily created on a SQL Server base table or view by using IOpenRowset::OpenRowset. Specify the table or view by name, passing the required rowset property sets in the rgPropertySets parameter.
Command text that creates a rowset is restricted when the consumer requires that the rowset be supported by a SQL Server cursor. Specifically, the command text is restricted to either a single SELECT statement that returns a single rowset result, or a stored procedure that implements a single SELECT statement returning a single rowset result.
When a SQL Server cursor supports a SQLOLEDB rowset, the number of elements in the row handle array parameter of IRowset::GetNextRows or IRowsetLocate::GetRowsAt defines the cursor block size. The rows indicated by the handles in the array are the members of the cursor block.
For rowsets supporting bookmarks, the row handles retrieved by using IRowsetLocate::GetRowsByBookmark define the members of the cursor block.
Regardless of the method used to populate the rowset and form the SQL Server cursor block, the cursor block is active as long as a reference is held by the consumer on the row handles retrieved.