Register a callback

For a callback to execute when its associated event occurs, you must register it with the mi_register_callback() function.

When you register a callback, you take the following actions:
  • Associate the callback function with the event it is to catch.
  • Provide arguments for the callback parameters.
The call to the mi_register_callback() function must occur before the statement for which you want the exception handling. If you register more than one callback to handle a particular event, all registered callbacks execute when the event occurs. The order in which these callbacks execute is not predetermined.
Tip: You do not need to register a callback function in the database with the CREATE FUNCTION statement. You need to register the callback only with the mi_register_callback() function.
The mi_register_callback() function requires the following arguments.
Argument type Description More information
MI_CONNECTION * A pointer to the connection on which the callback is to be registered. It might be NULL if the connection is undefined, as is the case with some client LIBMI errors and state-transition events. Connection descriptor
MI_EVENT_TYPE The event type that the callback handles Types of callbacks
MI_CALLBACK_FUNC A pointer to the callback function to invoke when the specified event occurs Callback-function pointer
void * A pointer to the user data, which is passed to the callback function when the specified event occurs. It can be used to pass additional information to and from the callback. Return error information to the caller

Manage memory allocations

MI_CALLBACK_HANDLE * Must be NULL Callback handle

These arguments initialize many of the parameters of the callback function. For more information, see Initializing a callback.

When mi_register_callback() registers the callback, the function returns a callback handle for the callback. For more information, see Callback handle.

If a callback is not registered when its event occurs, the DataBlade API takes the default behavior. For more information, see Default behavior.

By default, a callback remains registered until the end of the connection. For more information, see Registration duration.