Deploying a UDX on a Db2 instance

Deploying a UDX means moving its source code (and any other files it might need) to the host system, building its library (that is, the executable code that comprises it), and registering it. Only Db2® administrators are authorized to deploy UDXs. After a UDX is deployed, users can call it from within an SQL statement as they would any other SQL function.

To deploy a UDX using the CLPPlus command line interface:
  1. If you are a Db2 Warehouse user, you should use the version of CLPPlus that is in the Db2 Warehouse image container or client container. These versions of CLPPlus contain additional support. Although you must deploy the containers, no setup is required for CLPPlus afterward. For information about obtaining CLPPlus from the Db2 Warehouse client container, see Db2 Warehouse client container. Alternatively, you can install the Db2 Driver package as described in Db2 driver package. This package includes the CLPPlus command-line interface, including all the commands you will need to deploy and otherwise manage your UDXs.
  2. Connect CLPPlus as described in Connecting CLPPlus to a Db2 database.
    Note: If you are connecting to a database server on the same host as the client container, do not use localhost as host name. Instead, use a fully specified domain name, or 127.0.0.1 address to avoid a domain certificate mismatch. If such a mismatch happens, ida commands might not work.
  3. Create a file that contains the source code for your UDX. For example, you might create a file with the name tryp.cpp that contains the following C++ code that returns the product of two integers:
    #include "udxinc.h"
    #include <unistd.h>
    
    using namespace nz::udx_ver2;
    
    class CMyProduct: public nz::udx_ver2::Udf
    {
    public:
        CMyProduct(UdxInit *pInit) : Udf(pInit)
        {
        }
        static nz::udx_ver2::Udf* instantiate(UdxInit *pInit);
        virtual nz::udx_ver2::ReturnValue evaluate()
        {
            int int1= int32Arg(0);
            int int2= int32Arg(1);
            int retVal = int1 * int2;
    
            NZ_UDX_RETURN_INT32(retVal);
        }
    };
    nz::udx_ver2::Udf* CMyProduct::instantiate(UdxInit *pInit)
    {
        return new CMyProduct(pInit);
    }
    
  4. Create a compressed file that contains the UDX source-code file. For example:
    tar cvf proj.tar tryp.cpp
  5. In CLPPlus, issue the IDA DEPLOYUDX command to transfer the compressed file to the host, unpack it, compile and link the source code, and register the UDX. For example:
    ida deployudx source /home/mycode/proj.tar proj udxproj 
      sig tryproduct(int,int) return int fenced yes det yes nullcall yes 
      parallel yes class CMyProduct
  6. On the CLPPlus command line, enter SQL statements to create a simple table that you can use to test the UDX. For example:
    create table test1(col1 int, col2 int);
    insert into test1 values(10,20);
    insert into test1 values(20,30);
  7. On the CLPPlus command line, enter an SQL statement to invoke the UDX. For example:
    select tryproduct(col1,col2) from test1