Problem:
From the bottom of result set, start doing array fetches backward thru cursor using fetch previous-
when you get to the top, there are only 3 rows left to fetch ( array size is 5)
sqlerrd(3) is still set to 5 and sqlcode= 1
attempt to fetch before the result returns the first rowset
Resolution:
From MicroSoft:
It seems that this is expected behavior for SQL_FETCH_PRIOR. If the
fetch overlaps the beginning of the resultset, SQLFetchScroll() returns
SQLSTATE 01S06 (the message that you are seeing). SQLCODE will be 1
(SQL_SUCCESS_WITH_INFO).
The last fetch actually does return 5 rows, the 3 rows that you expect
plus an additional 2 rows from the previous fetch buffer. This explains
why SQLERRD3 is 5 rather than the 3 that you were expecting.
This behavior is by design from the ODBC specification document.
Recommendation: if you want to use scrolling with array fetches, code for this condition and do not allow another fetch previous when the last sqlcode was a 1. A fetch next will then pick up in the correct position.