Skip to content

Latest commit

 

History

History
57 lines (43 loc) · 3.08 KB

scrolling-and-fetching-rows.md

File metadata and controls

57 lines (43 loc) · 3.08 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic helpviewer_keywords
Scrolling and Fetching Rows
Scrolling and Fetching Rows
markingmyname
maghan
03/06/2017
sql
native-client
reference
scrollable cursors [SQL Server]
SQL Server Native Client ODBC driver, cursors
SQLFetchScroll function
ODBC applications, cursors
cursors [ODBC], fetching rows
ODBC cursors, fetching rows
cursors [ODBC], scrolling rows
fetching [ODBC]
ODBC cursors, scrolling rows

Scrolling and Fetching Rows

[!INCLUDESQL Server Azure SQL Database Synapse Analytics PDW]

To use a scrollable cursor, an ODBC application must:

  • Set the cursor capabilities using SQLSetStmtAttr.

  • Open the cursor using SQLExecute or SQLExecDirect.

  • Scroll and fetch rows using SQLFetch or SQLFetchScroll.

Both SQLFetch and SQLFetchSroll can fetch blocks of rows at a time. The number of rows returned is specified by using SQLSetStmtAttr to set the SQL_ATTR_ROW_ARRAY_SIZE parameter.

ODBC applications can use SQLFetch to fetch through a forward-only cursor.

SQLFetchScroll is used to scroll around a cursor. SQLFetchScroll supports fetching the next, prior, first, and last rowsets in addition to relative fetching (fetch the rowset n rows from the start of the current rowset) and absolute fetching (fetch the rowset starting at row n). If n is negative in an absolute fetch, rows are counted from the end of the result set. An absolute fetch of row -1 means to fetch the rowset that starts with the last row in the result set.

Applications that use SQLFetchScroll only for its block cursor capabilities, such as reports, are likely to pass through the result set a single time, using only the option to fetch the next rowset. Screen-based applications, on the other hand, can take advantage of all the capabilities of SQLFetchScroll. If the application sets the rowset size to the number of rows displayed on the screen and binds the screen buffers to the result set, it can translate scroll bar operations directly to calls to SQLFetchScroll.

Scroll bar operation SQLFetchScroll scrolling option
Page up SQL_FETCH_PRIOR
Page down SQL_FETCH_NEXT
Line up SQL_FETCH_RELATIVE with FetchOffset equal to -1
Line down SQL_FETCH_RELATIVE with FetchOffset equal to 1
Scroll box to top SQL_FETCH_FIRST
Scroll box to bottom SQL_FETCH_LAST
Random scroll box position SQL_FETCH_ABSOLUTE

In This Section

See Also

Using Cursors (ODBC)