For the ASE ODBC Driver

The following describes scrollable cursors for the ASE ODBC Driver.


Support for the Static Insensitive scrollable cursor

The ASE ODBC Driver supports the Static Insensitive scrollable cursor. It implements the ODBC SQLFetchScroll method to scroll and fetch rows. The SQLFetchScroll method is a standard ODBC method defined in Microsoft Open Database Connectivity Software Development Kit Programmer’s Reference, Volume 2, which is part of the MSDN library. Go to the Microsoft Web site for more information.

The ODBC driver supports the following scrolling types:


Setting scrollable cursor attributes

You must set the following attributes to use scrollable cursors:

The following are optional attributes when using scrollable cursors.


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);
    

Looking at results

After you execute a scrollable cursor, you will see these results, assuming a total of N rows and a rowset m where N > m:

Result

Interpretation

Absolute 0

No row is returned, error.

Absolute 1

m row is returned.

Absolute N

1 row is returned.

Absolute N+1

No row is returned, error.

First

The first (1..m ) rows are returned.

Last

The last (N-m+1 .. N) rows are returned.

Next

The same as SQLFetch().

Prior

Return the rowset that is before current rowset.

The following results are expected if the current cursor points to row k and k-a > 0, k + m + a < N, a>=0:

Result

Interpretation

Relative -a

The rows (k-a, k-a + m -1) are returned

Relative a

The rows (k + a, k+a + m -1) are returned


Implicit setting of scrolling cursor attributes

Certain attributes are set implicitly when your application sets specific attributes. The supported ODBC scrollable cursor attributes set implicitly are as follows:

Application sets attribute to

Other attributes set implicitly

SQL_ATTR_CONCURRENCY to SQL_CONCUR_READ_ONLY

SQL_ATTR_CURSOR_SENSITIVITY to SQL_INSENSITIVE

SQL_ATTR_CONCURRENCY to SQL_CONCUR_LOCK

SQL_ATTR_CURSOR_SENSITIVITY to SQL_SENSITIVE

SQL_ATTR_CURSOR_SCROLLABLE to SQL_NONSCROLLABLE

SQL_ATTR_CURSOR_TYPE to SQL_CURSOR_FORWARD_ONLY

SQL_ATTR_CURSOR_SENSITIVITY to SQL_INSENSITIVE

SQL_ATTR_CONCURRENCY to SQL_CONCUR_READ_ONLY SQL_ATTR_CURSOR_TYPE to SQL_CURSOR_STATIC

SQL_ATTR_CURSOR_TYPE to SQL_CURSOR_FORWARD_ONLY

SQL_ATTR_CURSOR_SCROLLABLE to SQL_NONSCROLLABLE

SQL_ATTR_CURSOR_TYPE to SQL_CURSOR_STATIC

SQL_ATTR_CURSOR_SCROLLABLE to SQL_SCROLLABLE