Example 1 Using FNC_GetAnyTypeParamInfo_eon - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

The following code excerpt is an example of a UDF that calls the FNC_GetAnyTypeParamInfo_eon function to retrieve information about the TD_ANYTYPE arguments.

#define SQL_TEXT Latin_Text
#include "sqltypes_td.h"

void ScalarFncWAnytype(void *input1,
                       ...,
                       void *result,
                       char sqlstate[6])
{
   anytype_param_info_eon_t paraminfo[2];
   FNC_GetAnyTypeParamInfo_eon(2*sizeof(anytype_param_info_eon_t), &numAnyType, paraminfo);

   if(((paraminfo[1].datatype == CHAR_DT) ||
       (paraminfo[1].datatype == VARCHAR_DT)) &&
       (paraminfo[1].paramIndex == -1) &&
       (paraminfo[1].direction == OUT_PM) &&
       (paraminfo[1].charset == LATIN_CT))
   {
      /* Process the value based upon the data type */
      switch(paraminfo[0].datatype)
      {
         case BYTEINT_DT:
            strcpy ((char *)result,"Byteint");
            break;
            /* Do some processing */
            ...
      }
   }
}

The following shows the corresponding SQL function definition:

REPLACE FUNCTION ScalarFncWAnytype ( p1 TD_ANYTYPE, ...)
   RETURNS TD_ANYTYPE
   NO SQL
   PARAMETER STYLE SQL
   RETURNS NULL ON NULL INPUT
   DETERMINISTIC
   LANGUAGE C
   EXTERNAL NAME 'CS!ScalarFncWAnytype!udfsrc/ScalarFncWAnytype.c';