Choosing Cursor Characteristics

Use cursors to carry out tasks for ODBC functions that execute statements and manipulate result sets.

Applications open a cursor implicitly when they execute a statement that returns a result set.

For applications that move through a result set only in a forward direction and do not update the result set, cursor behavior is relatively straightforward. By default, ODBC applications request this behavior. ODBC defines a read-only, forward-only cursor, and the Adaptive Server ODBC Driver provides a cursor optimized for performance in this case.

To set the required ODBC cursor characteristics, call the SQLSetStmtAttr function that defines statement attributes. Call SQLSetStmtAttr, before executing a statement that returns a result set.

You can use SQLSetStmtAttr to set cursor characteristics. The characteristic that determines the cursor type for the Adaptive Server ODBC Driver is SQL_ATTR_CONCURRENCY.

Set one of these values:
  • SQL_CONCUR_READ_ONLY - disallows updates. This is the default.

  • SQL_CONCUR_LOCK- uses the lowest level of locking needed to verify that the row is updated.

See SQLSetStmtAttr in the Microsoft ODBC Programmer's Reference.

For example, this fragment requests an updateable cursor:

SQLAllocHandle( SQL_HANDLE_STMT, dbc, &stmt );
SQLSetStmtAttr( stmt, SQL_ATTR_CONCURRENCY,
   SQL_CONCUR_LOCK, 0 );