Creating UDXs in C++C++ User Define Extensions (UDX) class-based routines
Creating a user-defined extension (UDX) in C++ involves designing the UDX, writing and debugging the underlying C++ code, and operational testing.
UDXs that are written in C++ can use the full standard C library (LIBC), but they should avoid interprocess communication (IPC) calls and other low-level operations. They cannot use global objects (static or otherwise) with constructors or destructors.
To create a UDX in C++:
- Identify the action that the user-defined extension is to perform. For example, you might require a function that performs tasks such as specialized string operations or comparisons; custom mathematical analysis; or conversions such as metric to English measurements, Celsius to Fahrenheit, or currency conversions.
Before the user-defined extensions feature, conversion and analysis tasks typically required users to export data from the database to do the processing and then load the converted data back into the database for storage. With user-defined extensions, you can do many or all of these analytical steps directly in the database.
- Review the existing SQL functions to confirm that your function is not already available as an SQL function. SQL offers a wide set of string, mathematical, analytical, and conversion functions. For example, if you want a function that changes the letter case of a string from uppercase to lowercase, or vice versa, SQL already provides LOWER() and UPPER() functions to do this.
- Write the C++ code that implements the necessary class methods and save it as a source file.
- Deploy (compile, link, promote, and register) the UDX as described in Deploying a UDX on a Db2 instance.
- Test and debug the UDX to identify and resolve any errors in the processing.
- If necessary, transfer the UDX to other database instances as described in Transferring a UDX from one Db2 instance to another. Users of those instances can use the UDX in their SQL queries in the same way that they would use any other SQL function.