Executing Scrollable Cursors

Use SQLBindCol() and SQLFetchScroll() APIs to execute a scrollable cursor.

  1. Set the scrollable cursor attributes for your environment.
  2. Bind the results.
    For example, add this code to your program:
    res=SQLBindCol(m_StatementHandle, 2, SQL_C_DOUBLE, price, 0, NULL);
    res=SQLBindCol(m_StatementHandle, 3, SQL_C_LONG, quantity, 0, NULL);
  3. Scroll and fetch by using SQLFetchScroll().
    For example, add this code to your program:
    res = SQLSetStmtAttr(m_StatementHandle, SQL_ATTR_CURSOR_SCROLLABLE,
       (SQLPOINTER)SQL_SCROLLABLE,SQL_IS_INTEGER);
    
    res = SQLSetStmtAttr(m_StatementHandle, SQL_ATTR_CURSOR_SENSITIVITY,
       (SQLPOINTER)SQL_INSENSITIVE, SQL_IS_INTEGER);
    
    
  4. Execute the Select statement.
    For example, add this code to your program:
    res = SQLExecDirect(m_StatementHandle, 
       (SQLCHAR "select price, quantity from book" SQL_NTS);
    res = SQLFetchScroll(m_StatementHandle, SQL_FETCH_NEXT,0);
    res = SQLFetchScroll(m_StatementHandle, SQL_FETCH_PRIOR,0);
    res = SQLFetchScroll(m_StatementHandle, SQL_FETCH_FIRST,0);
    res = SQLFetchScroll(m_StatementHandle, SQL_FETCH_LAST,0);
    res = SQLFetchScroll(m_StatementHandle, SQL_FETCH_ABSOLUTE,2);
    res = SQLFetchScroll(m_StatementHandle, SQL_FETCH_ABSOLUTE,-2);
    res = SQLFetchScroll(m_StatementHandle, SQL_FETCH_RELATIVE,1);
  5. Close the result set and the cursor.
    For example, add this code to your program:
    res = SQLFreeStmt(m_StatementHandle,SQL_CLOSE);
Related concepts
Scrollable Cursor Attributes