Freeing statement resources in CLI applications

After a transaction has completed, end the processing for each statement handle by freeing the resources associated with it.

About this task

There are four main tasks that are involved with freeing resources for a statement handle:
  • close the open cursor
  • unbind the column bindings
  • unbind the parameter bindings
  • free the statement handle

There are two ways you can free statement resources: using SQLFreeHandle() or SQLFreeStmt().

Before you can free statement resources, you must have initialized your CLI application and allocated a statement handle.

To free statement resources with SQLFreeHandle(), call SQLFreeHandle() with a HandleType of SQL_HANDLE_STMT and the handle you want to free. This will close any open cursor associated with this statement handle, unbind column and parameter bindings, and free the statement handle. This invalidates the statement handle. You do not need to explicitly carry out each of the four tasks listed previously.

Procedure

To free statement resources with SQLFreeStmt(), you need to call SQLFreeStmt() for each task (depending on how the application was implemented, all of these tasks may not be necessary):

  • To close the open cursor, call SQLCloseCursor(), or call SQLFreeStmt() with the SQL_CLOSE Option and statement handle as arguments. This closes the cursor and discards any pending results.
  • To unbind column bindings, call SQLFreeStmt() with an Option of SQL_UNBIND and the statement handle. This unbinds all columns for this statement handle except the bookmark column.
  • To unbind parameter bindings, call SQLFreeStmt() with an Option of SQL_RESET_PARAMS and the statement handle. This releases all parameter bindings for this statement handle.
  • To free the statement handle, call SQLFreeStmt() with an Option of SQL_DROP and the statement handle to be freed. This invalidates this statement handle.
    Note: Although this option is still supported, use SQLFreeHandle() in your CLI applications so that they conform to the latest standards.