DB2 Version 9.7 for Linux, UNIX, and Windows

Retrieving bulk data with bookmarks using SQLBulkOperations() in CLI applications

You can retrieve, or fetch, bulk data using bookmarks and the CLI SQLBulkOperations() function.

About this task

Bookmarks in CLI do not persist across cursor close operations. This means that an application cannot use bookmarks that it has stored from a previous cursor. Instead, it has to call SQLFetch() or SQLFetchScroll() to retrieve the bookmarks before updating with bookmarks.

To perform bulk fetches using bookmarks with SQLBulkOperations():

Before you begin

Before fetching bulk data using bookmarks and SQLBulkOperations(), ensure you have initialized your CLI application.

Procedure

  1. Set the SQL_ATTR_USE_BOOKMARKS statement attribute to SQL_UB_VARIABLE using SQLSetStmtAttr().
  2. Execute a query that returns a result set.
  3. Set the SQL_ATTR_ROW_ARRAY_SIZE statement attribute to the number of rows you want to fetch by calling SQLSetStmtAttr().
  4. Call SQLBindCol() to bind the data you want to fetch.

    The data is bound to an array with a size equal to the value of SQL_ATTR_ROW_ARRAY_SIZE.

  5. Call SQLBindCol() to bind column 0, the bookmark column.
  6. Copy the bookmarks for rows you want to fetch into the array bound to column 0.
    Note: The size of the array pointed to by the SQL_ATTR_ROW_STATUS_PTR statement attribute should either be equal to SQL_ATTR_ROW_ARRAY_SIZE, or the SQL_ATTR_ROW_STATUS_PTR statement attribute should be a null pointer.
  7. Fetch the data by calling SQLBulkOperations() with an Operation argument of SQL_FETCH_BY_BOOKMARK.

    If the application has set the SQL_ATTR_ROW_STATUS_PTR statement attribute, then it can inspect this array to see the result of the operation.

Results