Return a NULL value
To return most values from a user-defined function, you use a C return statement. To return the SQL NULL value, however, you must access the MI_FPARAM structure of the UDR.
The DataBlade
API provides
the following functions to support the return of an SQL NULL value
from a C user-defined function:
- To indicate that your user-defined function returns a NULL value, use the mi_fp_setreturnisnull() function to store the value of MI_TRUE at the appropriate index position in the null-return array of the MI_FPARAM structure.
- The mi_fp_returnisnull() function accesses the MI_FPARAM structure to determine whether a return value is NULL.
The mi_fp_setreturnisnull() function sets an mi_boolean value
to indicate whether the return value is NULL. The code fragment in Handling NULL arguments with MI_FPARAM implements the add_one() function
that uses the mi_fp_setreturnisnull() function
to return a NULL value when add_one() receives
a NULL argument.
Restriction: Do not return a NULL-valued pointer from
a UDR. If you need to have the UDR return an SQL NULL value, always
use mi_fp_setreturnisnull(). Otherwise, serious
memory corruption might occur.