informix
DataBlade Developers Kit User's Guide
Programming DataBlade Module Routines in C

Editing Routines in udr.c

BladeSmith generates code for the following types of routines in the udr.c source code file:

Most User-Defined Routines

BladeSmith generates only minimal code for most routines you create with the Routine wizard.

The Generated Code

BladeSmith generates only templates for most user-defined routines.

The generated routine declares the routine, its return type, and arguments. In addition to the arguments you specified when creating the routine, these functions also have an MI_FPARAM argument. Only generated routines that allow null values have code that uses the MI_FPARAM argument. The generated code in these routines uses MI_FPARAM to set the return value of the routine to NULL.

Completing the Code

To complete the code for most user-defined routines, you must:

For more information on programming routines, see the DataBlade API Programmer's Manual.

Examples

The following example DataBlade modules have user-defined routines:

The Mercury DataBlade module exercise in the tutorial provides examples of cast support functions.

Cast Support Functions

If you specified a cast support function when you created a cast, BladeSmith generates the cast support function in the udr.c file.

The Generated Code

BladeSmith generates only templates for cast support functions.

The generated function declares the routine, its return type, and arguments. In addition to the arguments you specified when creating the function, these functions also have an MI_FPARAM argument, which is not used by the generated code.

Completing the Code

To complete the code for cast support functions, you must:

In a cast support function, you might convert from one binary representation to another, if the data types involved in the cast have differing binary representations. Alternatively, you might perform a calculation to convert one data type to another.

Example

The Creating Distinct Types and Casts exercise in the tutorial uses cast support functions.

Aggregate Functions

If you created a user-defined aggregate with the Aggregate wizard, BladeSmith generates aggregate functions in the udr.c source code file.

The Generated Code

BladeSmith generates only templates for aggregate functions.

The generated function declares the function, its return type, and arguments. In addition to the arguments you specified when creating the function, these functions also have an MI_FPARAM argument. Only generated functions that allow null values have code that uses the MI_FPARAM argument. The generated code in these functions use the MI_FPARAM to set the return value of the function to NULL.

Completing the Code

To complete the code for aggregate functions, you must:

For more information on programming aggregate functions, see the DataBlade API Programmer's Manual.

The Initialization Function

If you selected an initialization function, AggregateInit(), you must add code to it to initialize the state type required by the aggregate computation. You can set up smart large objects or temporary files for storing intermediate results as the state type. The AggregateInit() function returns the state type.

The first argument of the AggregateInit() function is a dummy argument whose value is always NULL. The second argument is an optional initialization parameter to customize aggregate computation. The initialization parameter cannot be a lone host variable reference.

The Iteration Function

You must add code to the iteration function, AggregateIter(), to perform the aggregate computations.

The AggregateIter() function should not maintain additional states in its MI_FPARAM argument because the MI_FPARAM argument is not shared among the aggregate functions. However, you can use the MI_FPARAM argument to hold information that does not affect the aggregate result.

Tip: Although the iteration function is called by the database server multiple times to calculate the aggregation, it is not implemented as an iterator function that returns a set of results. The Combine Function

If you selected a combine function, AggregateComb(), you must add code to it to merge one partial result with another and return the updated state type.

The Final Function

If you selected a final function, AggregateFinl(), you must add code to convert the state type to the result type.

You can also add code to the AggregateFinl() function to release resources acquired by the initialization function. However, the AggregateFinl() function must not free the state type.

Selectivity Functions

If you create a user-defined function and mark it as a selectivity function for another function (see Selectivity Functions), BladeSmith generates the selectivity function in the udr.c source code file.

For a description of selectivity and user-defined statistics, see User-Defined Statistics.

The Generated Code

BladeSmith generates only templates for selectivity functions.

The generated code declares the function, its return type, and arguments. In addition to the arguments you specified when you created the function, BladeSmith also generates an MI_FPARAM argument, which is not used by the generated code.

Completing the Code

You must add code to the selectivity function to call the statistics support functions and calculate the selectivity of the associated function for a given set of arguments. For built-in data types, call the built-in statistics functions, such as StatCollect(). For opaque data types, call the statistics support functions in the statistics.c file, such as OpaqueStatCollect(). For more information on statistics support functions for opaque data types, see Editing Statistics Routines in statistics.c.

For example, if you have a selectivity function on an OpaqueEqual() function that is overloaded for an opaque data types, the code for the selectivity function, OpaqueEqualSelectivity(), might perform the following tasks:

For more information on coding selectivity functions, see the DataBlade API Programmer's Manual.

Example

The Box DataBlade module has selectivity functions.

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 iterator functions repeatedly to process all of the return values.

The Generated Code

In addition to the arguments you specified when creating it, an iterator function contains an MI_FPARAM argument. The Informix database server uses 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() function 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:

In the generated code, each of these sections has a TO DO: note. To avoid code merging problems, make changes only where indicated.

Completing the Code

To complete the iterator code, you must:

For more information on programming iterator functions, see the DataBlade API Programmer's Manual.

Example

The LoanAmortization() function in the Business DataBlade module is an iterator function.


DataBlade Developers Kit User's Guide, Version 4.0
Copyright © 1999, Informix Software, Inc. All rights reserved