You can use SQLBulkOperations() and
bookmarks to delete data in bulk.
Before you begin
Before deleting data in bulk, ensure you have initialized
your CLI application.
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.
Procedure
To perform bulk deletions using bookmarks and SQLBulkOperations():
- Set the SQL_ATTR_USE_BOOKMARKS statement attribute to SQL_UB_VARIABLE
using SQLSetStmtAttr().
- Execute a query that returns a result set.
- Set the SQL_ATTR_ROW_ARRAY_SIZE statement attribute to
the number of rows you want to delete.
- Bind the bookmark column to column 0 by calling SQLBindCol().
- 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.
- 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.