Cursors

Overview

Understanding cursors can be accomplished by understanding the following three questions:

The answer: it depends on the application! 

Cursor Type Meaning
Static
  • Membership in the set is constant (no records may be added or deleted)· 
  • After retrieving the set, changes made by other users to the database are not visible in the set (therefore, static)
Forward-Only
  • Can only move forward one at a time.
  • Because we cannot scroll backward, changes made by other users after the row was fetched are not visible (membership constant for fetched rows)·
  • Changes made by other uses are visible as a row is fetched (membership not constant for yet-to-be-fetched rows)
Keyset
  • Membership in the set is constant (no records may be added or deleted)· 
  • Only the primary key is retrieved.
  • As a record is processed (or accessed) its data is retrieved, therefore, we can see user changes but any added records.
Dynamic
  • Membership in the set is not constant.
  • The query is rerun as we process (access) each record.
  • It is possible to pick up any changes to the accessed record, and any newly added records.
CursorLocaiton = adUseServer
Lock Type  Cursor Type Requested
Forward-only Keyset  Dynamic  Static
Actual Cursor Type returned
Read-Only Forward-only Keyset Dynamic Static
Pessimistic Forward-only Keyset Dynamic Keyset
Optimistic Forward-only Keyset Dynamic Keyset
BatchOptimistic Forward-only Keyset Dynamic Keyset

 

CursorLocaiton = adUseClient
Lock Type  Cursor Type Requested
Forward-only Keyset  Dynamic  Static
Actual Cursor Type returned
Read-Only Static Static Static Static
Pessimistic Static Static Static Static
Optimistic Static Static Static Static
BatchOptimistic Static Static Static Static
Server-Side Cursors

dim oRS as new ADODB.Recordset
oRS.CursorLocation = adUseClient
set oRS = oCN.Execute("select * from T1")

Here oRS will inherit the CursorLocation property of the connection (default is adUseServer), overwriting the adUseClient property. To prevent this behavior use the Recordset.Open method.

oRS.Open "select * from T1", , adOpenKeyset, adLockBatchOptimistic

Client-Side Cursors