DataBlade Developers Kit User's Guide
Chapter 5: Programming DataBlade Module Routines in C
Home
Contents
Index
Master Index
New Book
User-Defined Routines, Casts, and Aggregates
If a BladeSmith project contains user-defined routines, casts, or aggregates, BladeSmith generates routines for them. The generated routine declares the routine, its return type, and parameters. The routine declares a local variable,
Gen_RetVal
, of the correct return data type.
Although these routines compile without error, you must add code to them so that they perform the intended operation.
Important:
Avoid code merge problems by modifying code only in the sections marked with a
TO DO:
note. If you do modify code outside the designated areas, after you regenerate you may have two copies of the routine: the one you modified, and the one BladeSmith generated. Although your changes remain, you must remove the duplicate routine code.
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 Informix database server calls this type of function repeatedly to process all of the return values, using an
MI_FPARAM
structure
to control iteration over the set. The generated code includes a C
switch
statement with different cases to process the set. The
switch
statement uses the
MI_FP_REQUEST()
macro to obtain the request flag from the
MI_FPARAM
structure. The Informix database server sets this flag to one of the following values before calling the function:
SET_INIT
. The initial call to the function. The function allocates and initializes memory for state information.
SET_RETONE
. The 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
variable and returns
Gen_RetVal
.
When there are no more values to return, the function uses the
MI_FP_SETISDONE()
macro to signal the Informix database server that all of the set values have been returned, as follows:
MI_FP_SETISDONE(Gen_fparam, MI_TRUE);
On this call, the function returns a null pointer.
SET_END
. The request flag the Informix database server sets after all values in the set have been returned. The 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, make changes only where indicated.
For an example of a function that returns sets, see the
LoanAmortization()
function in the
udr.c
example file for the Business DataBlade module.
Casts
Cast support functions convert one data type to another data type. The generated function takes a pointer to the "from" data type and returns a pointer to the "to" data type. You must add code to perform the conversion and store the result in the
Gen_RetVal
variable.
DataBlade Developers Kit User's Guide
, version 3.6
Copyright © 1998, Informix Software, Inc. All rights reserved.