Reuse the session-duration function descriptor
To reuse the session-duration function descriptor in another UDR,
you:
- Get the address of the PER_SESSION named-memory block that contains the function descriptor.
- Extract the address of the session-duration function descriptor from the named-memory block.
- Pass the session-duration function descriptor to the mi_routine_exec() function to execute the associated UDR.
The following code fragment shows how other UDRs can access the fdesc function
descriptor until the session ends:
MI_CONNECTION *sess_conn;
MI_FUNC_DESC **fdesc;
mi_integer status, error;
mi_integer i = 55;
mi_char ch = 'c';
MI_DATUM *value;
/* Obtain a public and session-duration connection
* descriptor
*/
conn = mi_open(NULL, NULL, NULL);
sess_conn = mi_get_session_connection();
/* Obtain the address of the 'funcptr_blk' named-memory block,
* which contains the session-duration function descriptor
*/
if ( (status = mi_named_get("funcptr_blk", PER_SESSION,
(void **)&fdesc)) != MI_OK )
{
/* Handle error */
...
}
/* Execute the UDR associated with the 'fdesc'
* session-duration function descriptor
*/
value = mi_routine_exec(conn, *fdesc, &error, i, c);
After you obtain the session-duration function descriptor, the mi_routine_exec() function can execute the associated UDR. You can specify either a public connection descriptor or a session-duration connection descriptor to mi_routine_exec(). If the UDR that the function descriptor references is dropped while the session-duration function descriptor is still in use, the database server generates an error when you try to execute the routine.