17.10 - Example - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

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';