How To

How to set cursor options (ODBC)

To set cursor options

Examples
A. Allocate a statement handle, set a dynamic cursor type with row versioning optimistic concurrency, and then execute a SELECT
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc1, &hstmt1);
retcode = SQLSetStmtAttr(hstmt1, SQL_ATTR_CURSOR_TYPE,
                  (SQLPOINTER)SQL_CURSOR_DYNAMIC,
                  SQL_IS_INTEGER);
retcode = SQLSetStmtAttr(hstmt1, SQL_ATTR_CONCURRENCY,
                  (SQLPOINTER)SQL_CONCUR_ROWVER,
                  SQL_IS_INTEGER);
retcode = SQLExecDirect(hstmt1,
                  "SELECT au_lname FROM authors",
                  SQL_NTS);
B. Allocate a statement handle, set a scrollable, sensitive cursor, and then execute a SELECT
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc1, &hstmt1);
// Set the cursor options and execute the statement.
retcode = SQLSetStmtAttr(hstmt1, SQL_ATTR_CURSOR_SCROLLABLE,
                  (SQLPOINTER)SQL_SCROLLABLE,
                  SQL_IS_INTEGER);
retcode = SQLSetStmtAttr(hstmt1, SQL_ATTR_CURSOR_SENSITIVITY,
                  (SQLPOINTER)SQL_INSENSITIVE,
                  SQL_IS_INTEGER);
retcode = SQLExecDirect(hstmt1,
                  "select au_lname from authors",
                  SQL_NTS);

See Also

Constructing SQL Statements for Cursors

SQLGetStmtAttr

SQLSetStmtAttr