Determine the data type of UDR arguments

With the MI_FPARAM structure, you can write UDRs that operate over a type hierarchy, rather than on a single type. At run time, the routine can examine the MI_FPARAM structure to determine what data types were passed to the current invocation of the routine.

The MI_FPARAM structure stores the information about each UDR argument in several parallel arrays.
Argument array Contents
Argument-type array Each element is a pointer to a type identifier (MI_TYPEID) that indicates the data type of the argument.
Argument-length array Each element is the integer length of the data type for each argument.
Argument-scale array Each element is the integer scale in the fixed-point argument.

The default value of the scale elements is zero. Therefore, any arguments that do not have a fixed-point data type have a scale value of zero.

Argument-precision array Each element is the integer precision in the fixed-point or floating-point argument.

The default value of the precision elements is zero. Therefore, any arguments that have neither fixed-point nor floating-point data types have a precision value of zero.

Parameter-null array Each element is either MI_FALSE or MI_TRUE:
  • MI_FALSE indicates that the argument is not an SQL NULL value.
  • MI_TRUE indicates that the argument is an SQL NULL value.

Use the appropriate MI_FPARAM accessor function in Argument information in an MI_FPARAM structure to access the desired argument array.

All the argument arrays in the MI_FPARAM structure have zero-based indexes. To access information for the nth argument, provide an index value of n-1 to the appropriate accessor function, as Argument information in an MI_FPARAM structure shows. The following figure shows how the information at index position 1 of these arrays holds the argument information for the second argument of the UDR.
Figure 1. Argument arrays in the MI_FPARAM structure
begin figure description - This figure is described in the surrounding text. - end figure description
The following calls to the mi_fp_argtype() and mi_fp_arglen() functions obtain the type identifier (arg_type) and length (arg_len) for the second argument from an MI_FPARAM structure that fparam_ptr identifies:
mi_integer my_func(arg0, arg1, arg2, fparam_ptr)
   MI_DATUM arg0;
   MI_DATUM arg1;
   MI_DATUM arg2;
   MI_FPARAM *fparam_ptr;
{
   MI_TYPEID *arg_type;
   mi_integer arg_len;
   ...
   arg_type = mi_fp_argtype(fparam_ptr, 1);
   arg_len = mi_fp_arglen(fparam_ptr, 1);

To obtain the number of arguments passed to the UDR (which is also the number of elements in the argument arrays), use the mi_fp_nargs() function. For the argument arrays of the MI_FPARAM structure in the preceding code fragment, mi_fp_nargs() would return a value of 3. The mi_fp_setnargs() function stores the number of routine arguments in the MI_FPARAM structure.