Before you begin to retrieve data, you need to establish the rowset that will be returned. This topic describes the steps associated with setting up the rowset.
To effectively work with a rowset, an application should perform the following steps:
#define ROWSET_SIZE 35
/* ... */
rc = SQLSetStmtAttr(hstmt,
SQL_ATTR_ROW_ARRAY_SIZE,
(SQLPOINTER) ROWSET_SIZE,
0);
/* ... */
SQLUINTEGER rowsFetchedNb;
/* ... */
rc = SQLSetStmtAttr(hstmt,
SQL_ATTR_ROWS_FETCHED_PTR,
&rowsFetchedNb,
0);
/* ... */
SQLUSMALLINT row_status[ROWSET_SIZE];
/* ... */
/* Set a pointer to the array to use for the row status */
rc = SQLSetStmtAttr(
hstmt,
SQL_ATTR_ROW_STATUS_PTR,
(SQLPOINTER) row_status,
0);
The row status array
provides additional information about each row in the rowset. After
each call to SQLFetch() or SQLFetchScroll(),
the array is updated. If the call to SQLFetch() or SQLFetchScroll() does
not return SQL_SUCCESS or SQL_SUCCESS_WITH_INFO, then the contents
of the row status array are undefined. Otherwise, any of the row
status array values will be returned (refer to the row status array
section of the SQLFetchScroll() documentation for
a complete list of values). SQLFetchScroll(hstmt, /* Statement handle */
SQL_FETCH_ABSOLUTE, /* FetchOrientation value */
11); /* Offset value */
Rowset retrieved | FetchOrientation value | Scroll bar |
---|---|---|
First rowset | SQL_FETCH_FIRST | Home: Scroll bar at the top |
Last rowset | SQL_FETCH_LAST | End: Scroll bar at the bottom |
Next rowset | SQL_FETCH_NEXT (same as calling SQLFetch()) | Page Down |
Previous rowset | SQL_FETCH_PRIOR | Page Up |
Rowset starting on next row | SQL_FETCH_RELATIVE with FetchOffset set to 1 | Line Down |
Rowset starting on previous row | SQL_FETCH_RELATIVE with FetchOffset set to -1 | Line Up |
Rowset starting on a specific row | SQL_FETCH_ABSOLUTE with FetchOffset set to an offset from the start (a positive value) or the end (a negative value) of the result set | Application generated |
Rowset starting on a previously bookmarked row | SQL_FETCH_BOOKMARK with FetchOffset set to a positive or negative offset from the bookmarked row | Application generated |
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.