A user-allocated MI_FPARAM structure (Server)

For C UDRs, one of the primary uses of a user-allocated MI_FPARAM structure is for data type control for generic routines. If you are calling a generic UDR, one that handles many possible data types, you can set the arguments in the MI_FPARAM structure to the specific data type.

Possible uses for generic UDRs include over collection types or over type hierarchies. You can set the MI_FPARAM structure to accept the correct parameter data types for a particular invocation of the routine. For example, you can pass an employee_t data type into a UDR that was defined with the supertype person_t.

Suppose you have a type hierarchy with person_t as the supertype and employee_t as a subtype of person. The person_udr() UDR might be called with either the person_t or employee_t data type in the first two arguments. Suppose person_udr() needs to use Fastpath to execute another UDR, named person_udr2(), to handle some additional task. The following code fragment shows how the second and third arguments from person_udr() are passed to person_udr2():
person_udr(person1, person2, data, fparam)
   pers_type *person1;
   pers_type *person2;
   mi_lvarchar *data;
   MI_FPARAM *fparam;
{
   MI_TYPEID *pers2_typeid;
   MI_FUNC_DESC *my_funcdesc;
   MI_FPARAM *my_fparam;
   mi_integer *myint_error;

   ...

   pers2_typeid = mi_fp_argtype(fparam, 1);
   my_funcdesc = mi_routine_get(conn, 0, 
      "myfunc(person_t, lvarchar)");
   my_fparam = mi_fparam_get(conn, my_funcdesc);
   mi_fp_setargtype(my_fparam, 0, pers2_typeid);
   mi_routine_exec(conn, my_funcdesc, &myint_error, person2,
      data, my_fparam);
...
}
In the preceding code fragment, the first argument of person_udr2() is set to have the same type as the second argument of person_udr(), based on its MI_FPARAM structure. In this implementation, person_udr2() needs the actual data type of the argument, not the supertype.
Tip: Another possible use of a user-allocated MI_FPARAM structure is in conjunction with per-session function descriptors. Per-session function descriptors are an advanced feature of the DataBlade® API.