Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - Programming » Application development using SQL » Cursor principles

 

Row fetching through a cursor

The simplest way of processing the result set of a query using a cursor is to loop through all the rows of the result set until there are no more rows. You can accomplish this task by performing these steps:

  1. Declare and open the cursor (embedded SQL), or execute a statement that returns a result set (ODBC, JDBC, Open Client) or SADataReader object (ADO.NET).

  2. Continue to fetch the next row until you get a Row Not Found error.

  3. Close the cursor.

The technique used to fetch the next row is dependent on the interface you use. For example:

  • ADO.NET   Use the SADataReader.Read method. See SADataReader.Read method [SQL Anywhere .NET].

  • ODBC   SQLFetch, SQLExtendedFetch, or SQLFetchScroll advances the cursor to the next row and returns the data.

    For more information about using cursors in ODBC, see Result sets in ODBC applications.

  • JDBC   The next method of the ResultSet object advances the cursor and returns the data.

    For more information about using the ResultSet object in JDBC, see How to return result sets from Java.

  • Embedded SQL   The FETCH statement carries out the same operation.

    For more information about using cursors in embedded SQL, see Cursors in embedded SQL.

  • Open Client   The ct_fetch function advances the cursor to the next row and returns the data.

    For more information about using cursors in Open Client applications, see Open Client cursor management.