DB2 Version 9.7 for Linux, UNIX, and Windows

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

You can use SQLBulkOperations() and bookmarks to delete data in bulk.

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 by bookmarks.

To perform bulk deletions using bookmarks and SQLBulkOperations():

Before you begin

Before deleting data in bulk, 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 delete.
  4. Bind the bookmark column to column 0 by calling SQLBindCol().
  5. Copy the bookmarks for the rows you want to delete 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.
  6. Perform the deletion by calling SQLBulkOperations() with an Operation argument of SQL_DELETE_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