This section describes the functions and files you must create to call a UDF.
For each UDF that you want called, you will create two functions:
The UDF: Gets the context parameter from the server, unpacks the intended parameters from the context parameter, and then processes them.
If you already have a function that does what you want, you can use an intermediate function that gets the context parameter from the server, unpacks the intended parameters from the context parameter, and then calls your function. This intermediate function also packs the output value into the context variable and returns an error indicator. Both functions will be put in the same library.
You will create two files:
A library file that contains your function and the corresponding intermediate function.
An XML file that lists the name of the library, the name of the intermediate function, and the data types of the parameters in the UDF.
UDFs: Cautions
Because your UDF can be called from multiple queries, or multiple places in the same query, your C code should be re-entrant. Specifically, it should avoid static variables.
Your UDF should free any memory that it allocates unless the Sybase CEP API description specifically states that the Sybase CEP library function will free the memory.
Your UDF should not free any memory that is passed to it unless the Sybase CEP API description specifically states that the user should free the memory. For example, do not free the context variable that is passed to the UDF.
In CCL statements, your function should be used as a per-row function, not as an aggregate function such as SUM, AVG, and so on.
Since the server reads the library file and the XML description of the UDF at the time that the server starts, changes to the library file or XML file will not take effect until the next time that the server starts.
Since the UDF runs as part of the server, an error in the UDF can cause the server to crash. Your UDF should be thoroughly tested before you use it in a production system.
You should explicitly handle the following:
Error conditions that occur inside your own UDF.
NULL input values.