Executing scrollable cursors

StepsTo set up a program to execute a scrollable cursor

  1. Set the scrollable cursor attributes for your environment.

    See “Setting scrollable cursor attributes” for more information.

  2. Bind the results. For example, add the following 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 the following 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);
    
    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);
    
  4. Execute the Select statement. For example, add the following to your program:

    res = SQLExecDirect(m_StatementHandle, (SQLCHAR "select price, quantity from book" SQL_NTS);
    
  5. Close the result set and the cursor. For example, add the following to your program:

    res = SQLFreeStmt(m_StatementHandle,SQL_CLOSE);