Document each UDX
Develop a documentation and comments convention for each UDX. One method is to include all the necessary commands and sample usage at the top of the C++ file as a comment. This can help you to reconstruct the purpose, compilation code, registration arguments, and any additional information such as table format for your functions.
The following example shows a complete listing of the customername.cpp file
with both the code and documentation comments at the beginning of
the file.
/*
Copyright (c) 2007-2014 IBM Corp.
All rights reserved.
Function CustomerName takes a string and returns an integer 1 if it
begins with 'Customer A' and 0 otherwise.
REGISTRATION:
create or replace function
CustomerName(varchar(32672))
returns INTEGER
language cpp
parameter style npsgeneric
EXTERNAL 'customername!CCustomerName';
USAGE:
create table customers (a int, b varchar(200));
insert into customers values (1,'Customer A');
insert into customers values (2,'Customer B');
insert into customers values (3,'Customer CBA');
insert into customers values (4,'Customer ABC');
select * from customers where CustomerName(b) = 1;
*/
#include "udxinc.h"
#include <string.h>
using namespace nz::udx_v2;
class CCustomerName: public Udf
{
public:
static Udf* instantiate();
virtual ReturnValue evaluate()
{
StringArg *str;
str = stringArg(0);
int lengths = str->length;
char *datas = str->data;
int32 retval = 0;
if (lengths >= 10)
if (memcmp("Customer A",datas,10) == 0)
retval = 1;
NZ_UDX_RETURN_INT32(retval);
}
};
Udf* CCustomerName::instantiate()
{
return new CCustomerName;
}