滚动和提取行 (ODBC)Scrolling and Fetching Rows (ODBC)

使用可滚动游标时,应用程序调用 SQLFetchScroll 来定位游标并提取行。When using a scrollable cursor, applications call SQLFetchScroll to position the cursor and fetch rows. SQLFetchScroll 支持相对滚动 (next、前期和相对 n 行) ,绝对滚动 (first、last 和 row n) ,并按书签定位。SQLFetchScroll supports relative scrolling (next, prior, and relative n rows), absolute scrolling (first, last, and row n), and positioning by bookmark. SQLFetchScroll中的FetchOrientationFetchOffset参数指定要提取的行集,如下图所示。The FetchOrientation and FetchOffset arguments in SQLFetchScroll specify which rowset to fetch, as shown in the following diagrams.

提取下一个行集、上一个行集、第一个行集和最后一个行集Fetching Next, Prior, First, and Last Rowsets

提取下一个行集、上一个行集、第一个行集和最后一个行集Fetching Next, Prior, First, and Last Rowsets

提取绝对行集、相对行集和书签行集Fetching Absolute, Relative, and Bookmarked Rowset

提取绝对、相对和书签的行集Fetching Absolute, Relative, and Bookmarked Rowsets

SQLFetchScroll 将游标定位到指定的行,并以该行开头返回行集中的行。SQLFetchScroll positions the cursor to the specified row and returns the rows in the rowset starting with that row. 如果指定的行集与结果集的末尾重叠,则返回部分行集。If the specified rowset overlaps the end of the result set, a partial rowset is returned. 如果指定的行集与结果集的开头重叠,则通常返回结果集中的第一个行集;有关完整的详细信息,请参阅 SQLFetchScroll 函数说明。If the specified rowset overlaps the start of the result set, the first rowset in the result set is usually returned; for complete details, see the SQLFetchScroll function description.

在某些情况下,应用程序可能需要在不检索任何数据的情况下定位游标。In some cases, the application might want to position the cursor without retrieving any data. 例如,它可能需要测试行是否存在,或者只是获取行的书签,而不会在网络中引入其他数据。For example, it might want to test whether a row exists or just get the bookmark for the row without bringing other data across the network. 为此,它会将 SQL_ATTR_RETRIEVE_DATA 语句特性设置为 SQL_RD_OFF。To do this, it sets the SQL_ATTR_RETRIEVE_DATA statement attribute to SQL_RD_OFF. 如果始终更新任何) ,则绑定到 bookmark 列的变量 (,而不考虑此语句特性的设置。The variable bound to the bookmark column (if any) is always updated, regardless of the setting of this statement attribute.

检索到行集之后,应用程序可以调用 SQLSetPos ,以便定位到行集中的特定行或刷新行集中的行。After the rowset has been retrieved, the application can call SQLSetPos to position to a particular row in the rowset or refresh rows in the rowset. 有关使用 SQLSetPos的详细信息,请参阅 使用 SQLSetPos 更新数据For more information on using SQLSetPos, see Updating Data with SQLSetPos.

备注

ODBC 2 支持滚动。x 驱动程序 SQLExtendedFetchScrolling is supported in ODBC 2.x drivers by SQLExtendedFetch. 有关详细信息,请参阅附录 G:驱动程序准则中的 块游标、可滚动游标和后向兼容性For more information, see Block Cursors, Scrollable Cursors, and Backward Compatibilityin Appendix G: Driver Guidelines for Backward Compatibility.