Changing parameter bindings in CLI applications with offsets

When an application needs to change parameter bindings, it can call SQLBindParameter() a second time. This will change the bound parameter buffer address and the corresponding length/indicator buffer address used. Instead of multiple calls to SQLBindParameter(), however, CLI also supports parameter binding offsets. Rather than re-binding each time, an offset can be used to specify new buffer and length/indicator addresses which will be used in a subsequent call to SQLExecute() or SQLExecDirect().

Before you begin

Before changing your parameter bindings, ensure that your application has been initialized.

Procedure

To change parameter bindings by using offsets:

  1. Call SQLBindParameter() as you had been to bind the parameters.

    The first set of bound parameter buffer addresses and the corresponding length/indicator buffer addresses will act as a template. The application will then move this template to different memory locations using the offset.

  2. Call SQLExecute() or SQLExecDirect() as you had been to execute the statement.

    The values stored in the bound addresses will be used.

  3. Initialize a variable to hold the memory offset value.

    The statement attribute SQL_ATTR_PARAM_BIND_OFFSET_PTR points to the address of an SQLINTEGER buffer where the offset will be stored. This address must remain valid until the cursor is closed.

    This extra level of indirection enables the use of a single memory variable to store the offset for multiple sets of parameter buffers on different statement handles. The application need only set this one memory variable and all of the offsets will be changed.

  4. Store an offset value (number of bytes) in the memory location pointed to by the statement attribute set in the previous step.

    The offset value is always added to the memory location of the originally bound values. This sum must point to a valid memory address.

  5. Call SQLExecute() or SQLExecDirect() again. CLI will add the offset value to the location used in the original call to SQLBindParameter() to determine where the parameters to be used are stored in memory.
  6. Repeat steps 4 and 5 as required.