When an application needs to change
bindings (for a subsequent fetch, for example) it can call SQLBindCol() a
second time.
This will change the buffer address and length/indicator
pointer used. Instead of multiple calls to SQLBindCol(), CLI supports
column 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 SQLFetch() or SQLFetchScroll().
Before you begin
Before using column binding offsets to change result set
bindings, ensure you have initialized your CLI application.
About this task
This method can only be used with row-wise binding, but
will work whether the application retrieves a single row or multiple
rows at a time.
Procedure
To change result set bindings using column binding offsets:
- Call SQLBindCol() as usual to bind the
result set. The first set of bound data buffer and length/indicator
buffer addresses will act as a template. The application will then
move this template to different memory locations using the offset.
- Call SQLFetch() or SQLFetchScroll() as
usual to fetch the data. The data returned will be stored in the locations
bound in step 1.
- Set up a variable to hold the memory offset value.
The statement attribute SQL_ATTR_ROW_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 bindings on different statement
handles. The application need only set this one memory variable and
all of the offsets will be changed.
- 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 with sufficient space to hold the next set of data.
- Call SQLFetch() or SQLFetchScroll() again. CLI will
add the offset value to the locations used in the original call to SQLBindCol().
This will determine where in memory to store the results.
- Repeat steps 4 and 5 as required.