Determine if a UDR handles NULL arguments

Before you execute a UDR with the Fastpath interface, you can determine whether this routine handles SQL NULL values as arguments. If the current argument values are SQL NULL values and the UDR does not handle NULL values, you do not need to call the UDR.

By default, a C UDR does not handle NULL values. When the routine manager receives NULL arguments for such a UDR, it does not even invoke the UDR. It just returns a NULL value.

To determine whether the UDR or cast function that a function descriptor describes can handle SQL NULL values as arguments, use the mi_func_handlesnulls() function. This function determines whether the UDR was registered with the HANDLESNULLS routine modifier of the CREATE FUNCTION or CREATE PROCEDURE statement (stored in the handlesnulls column of the sysprocedures system catalog table).

The mi_func_handlesnulls() function indicates whether a UDR can handle SQL NULL values, as follows.
1
The routine that the function descriptor describes has been registered with the HANDLESNULLS routine modifier.
2
The routine that the function descriptor describes has not been registered with the HANDLESNULLS routine modifier.
The following code fragment determines whether to invoke the numeric_func() function based on whether it handles NULL arguments.
MI_CONNECTION *conn;
MI_FUNC_DESC *fdesc;
MI_FPARAM *fdesc_fparam;
MI_DATUM ret_val;
mi_integer error;
...
fdesc = mi_routine_get(conn, 0, 
   "function numeric_func(integer, integer)");

/* Determine whether to execute the UDR */
if ( mi_func_handlesnulls(fdesc) == 1 )
   {
   fdesc_fparam = mi_fparam_get(conn, fdesc);
   mi_fp_setargisnull(fdesc_fparam, 0, MI_TRUE);
   ret_val = mi_routine_exec(conn, fdesc, &error, 0, 2);
   }
else
   /* have numeric_func() return zero if it has NULL args */
   ret_val = 0;

If numeric_func() handles NULL arguments, the mi_func_handlesnulls() function returns 1 and the code fragment invokes numeric_func() with arguments of NULL and 2. The code fragment uses the mi_fparam_get() and mi_fp_setargisnull() functions to set the first argument to an SQL NULL value.

If numeric_func() does not handle NULL arguments, the code fragment does not invoke numeric_func(); instead, it sets the return value of numeric_func() to zero.