DB2 Version 9.7 for Linux, UNIX, and Windows

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

You can update data in bulk with bookmarks using SQLBulkOperations().

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.

Before you begin

Before updating data in bulk, ensure you have initialized your CLI application.

Procedure

To update data in bulk:

  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 update using SQLSetStmtAttr().
  4. Call SQLBindCol() to bind the data you want to update.

    The data is bound to an array with a size equal to the value of SQL_ATTR_ROW_ARRAY_SIZE, set in the previous step.

  5. Bind the bookmark column to column 0 by calling SQLBindCol().
  6. Copy the bookmarks for rows that you want to update into the array bound to column 0.
  7. Update the data in the bound buffers.
    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 SQL_ATTR_ROW_STATUS_PTR should be a null pointer.
  8. Update the data by calling SQLBulkOperations() with an Operation argument of SQL_UPDATE_BY_BOOKMARK.
    Note: 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.
  9. Optional: Verify that the update has occurred by calling SQLBulkOperations() with an Operation argument of SQL_FETCH_BY_BOOKMARK. This will fetch the data into the bound application buffers.

    If data has been updated, CLI changes the value in the row status array for the appropriate rows to SQL_ROW_UPDATED.

    Note: If SQLBulkOperations() is called with an Operation argument of SQL_UPDATE_BY_BOOKMARK on a cursor that contains duplicate columns, an error is returned.