Creating UDR code
This section provides an overview of C UDR development.
Tip: For a discussion of special implementation
issues specific to a C UDR, see Write a user-defined routine.
- Variable declaration
In a C UDR, you declare variables to hold information just as you would in a C function. The DataBlade API provides many data types for variable declaration. - Session management
Session management is different in a C UDR than in a client LIBMI application. Unlike a client LIBMI application, which can simultaneously connect to several databases, a UDR inherits a particular session context. That is, it is within an existing session and uses a database that is already opened. - SQL statement execution
The differences in the execution of SQL statements in a C UDR and a client LIBMI application are because of the differences in passing mechanisms that they use for the contents of an MI_DATUM structure. In a C UDR, you must consider the data type of the value in the MI_DATUM structure to determine how to obtain the value. - Routine-state information
When the routine manager executes a C UDR, it puts information about the routine sequence for the UDR in an MI_FPARAM structure and passes this MI_FPARAM structure as the last argument to the UDR. - Event handling
Your C UDR must perform event handling to ensure recovery from unexpected results, usually a warning or runtime error from the database server. To handle warnings and errors, the C UDR can define callback functions that the DataBlade API invokes when a particular event occurs. - Well-behaved routines
The most efficient way for a C UDR to execute is in the CPU virtual-process (CPU VP) class. However, to execute in the CPU VP, the UDR must be well-behaved. A well-behaved UDR adheres to a set of safe-code requirements that prevent the UDR from interfering with the efficient operation of the CPU VP.
Parent topic: Develop a user-defined routine