Iterator functions
If you create an iterator function that returns a set one row at a time, BladeSmith adds code to process the set. The HCL OneDB™ database server calls iterator functions repeatedly to process all of the return values.
The generated code
Request flag | Description |
---|---|
SET_INIT |
The initial call to the iterator function. The iterator function allocates and initializes memory for state information. The memory allocated must use the mi_alloc(size, PER_COMMAND) function to be available in subsequent calls. |
SET_RETONE |
The iterator function is called with this request
flag once for each value in the set. For each value in the set, the function places the address of the next value in the set in the Gen_RetVal argument and returns Gen_RetVal. When there are no more values
to return, the iterator function must call the mi_fp_setisdone() function
to signal the HCL
OneDB database
server that all of the set values have been returned, as follows:
On this call, the iterator function returns a null pointer. |
SET_END |
The request flag the HCL OneDB database server sets after all values in the set have been returned. The iterator function frees allocated memory and releases any other resources it has obtained. |
In the generated code, each of these sections has a TO
DO:
note. To avoid code merging problems, only change sections
where indicated.
Complete the code
- Add information declarations.
- Initialize the iterator function.
- Allocate private state information.
- Compute the value of the iteration.
- Call mi_fp_setisdone() when the iteration is complete.
- Free private resources.
For more information about programming iterator functions, see the HCL OneDB DataBlade® API Programmer's Guide.
Example
The LoanAmortization() function in the Business DataBlade module is an iterator function.