Determine the data type of UDR return values

The database server sets the return-value data type of the user-defined function. Most user-defined functions might need to check the return-value data type but they do not need to set it. The routine manager uses the return-value information to determine how to bind the return value to a return variable or an SQL value.

You need to access return-value information only if your UDR needs to perform one of the following tasks:
  • Override the expected return type (for type hierarchies).

    You can set this return-value data type in the MI_FPARAM structure

  • Set the actual length, precision, or scale of the return value.
  • Return an SQL NULL value.
  • Check the return value of a UDR that you are going to execute with the Fastpath interface and for which you have created a user-allocated MI_FPARAM structure.

If your UDR does not need to perform these tasks, it does not need to modify return-value information in the MI_FPARAM structure.

The MI_FPARAM structure uses several parallel arrays to store the following information about each return value.
Return-value array Contents
Return-type array Each element is a pointer to a type identifier (MI_TYPEID) that indicates the data type of the return value.
Return-length array Each element is the integer length of the data type for each return value.
Return-scale array Each element is the integer scale in the fixed-point return value.
Return-precision array Each element is the integer precision of the fixed-point or floating-point return value.
Return-null array Each element has either of the following values:
  • MI_FALSE: The return value is not an SQL NULL value.
  • MI_TRUE: The return value is an SQL NULL value.

Use the appropriate MI_FPARAM accessor function in Return-value information in the MI_FPARAM structure to access the desired return-value array.

All of the return-value arrays in the MI_FPARAM structure have zero-based indexes. To access information for the nth return value, provide an index value of n-1 to the appropriate accessor function in Return-value information in the MI_FPARAM structure. The following figure shows how the information at index position 0 of these arrays holds the return-value information for the first (and only) return value of a user-defined function.
Figure 1: Return-value 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_rettype() and mi_fp_retlen() functions obtain the type identifier (ret_type) and length (ret_len) for the first (and only) return value from an MI_FPARAM structure that fparam_ptr identifies:
MI_FPARAM *fparam_ptr;
MI_TYPEID *ret_type;
mi_integer ret_len;
...
ret_type = mi_fp_rettype(fparam_ptr, 0);
ret_len = mi_fp_retlen(fparam_ptr, 0);

To obtain the number of return values of the user-defined function, use the mi_fp_nrets() function. However, the number of return values is always 1 for a C user-defined function. The mi_fp_setnrets() function stores the number of return values in the MI_FPARAM structure.