Example: Add logMsg() to the sample UDF
virtual ReturnValue evaluate()
{
StringArg *str; // 3
str = stringArg(0); // 4
int lengths = str->length; // 6
char *datas = str->data; // 7
int32 retval = 1;
if (lengths >= 10)
if (memcmp("Customer A",datas,10) == 0)
{
logMsg(LOG_DEBUG, "Found a match of length %d\n", lengths);
// 14
retval = 1;
}
NZ_UDX_RETURN_INT32(retval); // 17
}nzudxcompile customername.cpp –o customername.oCREATE OR REPLACE FUNCTION CustomerName(varchar(64000))
RETURNS int4 LANGUAGE cpp PARAMETER STYLE npsgeneric
EXTERNAL CLASS NAME 'CCustomerName'
EXTERNAL HOST OBJECT '/home/nz/myfirstudx/customername.o_x86'
EXTERNAL SPU OBJECT '/home/nz/myfirstudx/customername.o_spu10';ALTER FUNCTION CustomerName(varchar(64000)) LOGMASK DEBUG,TRACE;The values for LOGMASK can be NONE, DEBUG, TRACE, or both DEBUG, TRACE. The value NONE disables output; DEBUG outputs any calls to logMsg() that contain LOG_DEBUG; TRACE outputs any messages with LOG_TRACE as the flag; DEBUG, TRACE outputs messages that have either or both DEBUG and TRACE flags.
If you use the --file argument of the nzudxdbg command, the output messages are written to the standard log files. Log the messages to files to help with debugging and comparisons of the output messages after the test runs.
nzstop
nzstart -iYou do not have to restart the database after each time you change the function, only after the first time that you enable message logging in that specific terminal window.
nzudxdbg --user admin --pw password -–on --fileselect * from customers where CustomerName(b) = 1;
(event002.1001) [d,udx ] Found a match of length 12
(event002.1003) [d,udx ] Found a match of length 10
The (event002.1001) identifies where the function was run. It means that it was in process event002 on the SPU with hardware ID 1001 (or 1003 in the second message).
select x.*, customername(x.b) from customers x, customers y;
07-24-07 16:29:07 (dbos.24072) [d,udx ] Found a match of length 10 07-24-07 16:29:07 (dbos.24072) [d,udx ] Found a match of length 10 07-24-07 16:29:07 (dbos.24072) [d,udx ] Found a match of length 10 07-24-07 16:29:07 (dbos.24072) [d,udx ] Found a match of length 12 07-24-07 16:29:07 (dbos.24072) [d,udx ] Found a match of length 12 07-24-07 16:29:07 (dbos.24072) [d,udx ] Found a match of length 12 07-24-07 16:29:07 (dbos.24072) [d,udx ] Found a match of length 12
The (dbos.24072) value indicates that the message occurred in the dbos process with process ID (pid) 24072.