DB2 Version 9.7 for Linux, UNIX, and Windows

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

You can insert 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.

To perform a bulk data insert using SQLBulkOperations():

Before you begin

Before inserting bulk data with 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 insert using SQLSetStmtAttr().
  4. Call SQLBindCol() to bind the data you want to insert.

    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.

    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.
  5. Insert the data by calling SQLBulkOperations() with SQL_ADD as the Operation argument.

    CLI will update the bound column 0 buffers with the bookmark values for the newly inserted rows. For this to occur, the application must have set the SQL_ATTR_USE_BOOKMARKS statement attribute to SQL_UB_VARIABLE before executing the statement.

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

Results