Example 2 Using FNC_GetAnyTypeParamInfo - 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 shows an external stored procedure that calls the FNC_GetAnyTypeParamInfo function to retrieve information about the TD_ANYTYPE arguments.

#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>

void xspwanytypefnc(void     *input1,
                    ...,
                    void     *result,
                    int      *indc_input1,
                    ...,
                    int      *indc_result,
                    char     sqlstate[6],
                    SQL_TEXT extname[129],
                    SQL_TEXT specific_name[129],
                    SQL_TEXT error_message[257])
{
   anytype_param_info_t paraminfo[2];
   int numunk;

   FNC_GetAnyTypeParamInfo(2*sizeof(anytype_param_info_t),&numunk,
      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 procedure definition:

CREATE PROCEDURE xspwanytypefnc(IN a TD_ANYTYPE,
                                ...,
                                OUT result1 TD_ANYTYPE)
LANGUAGE C
NO SQL
PARAMETER STYLE SQL
EXTERNAL NAME 'CS!xspwanytypefnc!xspwanytypefnc.c';