Rowset retrieval examples in CLI applications

The rowset is a cache that holds predefined rows of data that are returned in the result set.

Partial rowset example

The application cannot assume that the entire rowset will contain data. It must check the row status array after each rowset is created to determine the number of rows returned, because there are instances where the rowset will not contain a complete set of rows. For instance, consider the case where the rowset size is set to 10, and SQLFetchScroll() is called using SQL_FETCH_ABSOLUTE and FetchOffset is set to -3. This will attempt to return 10 rows starting 3 rows from the end of the result set. Only the first three rows of the rowset will contain meaningful data, however, and the application must ignore the rest of the rows.

Figure 1. Partial rowset example
Partial rowset example

Fetch orientations example

The following figure demonstrates a number of calls to SQLFetchScroll() using various FetchOrientation values. The result set includes all of the rows (from 1 to n), and the rowset size is 3. The order of the calls and the FetchOrientation values are as follows:
  1. SQL_FETCH_LAST
  2. SQL_FETCH_FIRST
  3. SQL_FETCH_NEXT
  4. SQL_FETCH_RELATIVE
  5. SQL_FETCH_ABSOLUTE
Figure 2. Example of retrieving rowsets
Example of retrieving rowsets