17.10 - Examples - 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)

Example: UDM with Parameter Style TD_GENERAL

Here is a code excerpt that shows how to declare a C function for a UDM that uses parameter style TD_GENERAL:

/*****  C source file name: to_inches.c  *****/
   
#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>
   
void meters_toInches( UDT_HANDLE  *meterUDT
                      FLOAT       *result,
                      char         sqlstate[6])
{
     ...
}

For a complete example of the C function, see UDM Code Examples.

The CREATE TYPE statement to create the UDT with which the method is associated looks like this:

CREATE TYPE meter AS FLOAT
FINAL
   INSTANCE METHOD toInches()
   RETURNS FLOAT
   SPECIFIC toInches
   NO SQL
   PARAMETER STYLE TD_GENERAL
   DETERMINISTIC
   LANGUAGE C;

The corresponding CREATE METHOD statement to install the UDM on the server looks like this:

CREATE METHOD toInches()
RETURNS FLOAT
FOR meter
EXTERNAL NAME 'CS!toinches!udm_src/to_inches.c!F!meters_toInches';

Example: UDM with Parameter Style SQL

Here is an example of how to declare a C function for a UDM that uses parameter style SQL:

/*****  C source file name: to_inches.c  *****/
  
#define  SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>
   
void meters_toInches( UDT_HANDLE  *meterUDT
                      FLOAT       *result,
                      int         *meterUDTIsNull,
                      int         *resultIsNull,
                      char         sqlstate[6])
                      SQL_TEXT     extname[129],
                      SQL_TEXT     specific_name[129],
                      SQL_TEXT     error_message[257] )
{
     ...
}

For a complete example of the C function, see UDM Code Examples.

The CREATE TYPE statement to create the UDT with which the method is associated looks like this:

CREATE TYPE meter AS FLOAT
FINAL
   INSTANCE METHOD toInches()
   RETURNS FLOAT
   SPECIFIC toInches
   NO SQL
   PARAMETER STYLE SQL
   DETERMINISTIC
   LANGUAGE C;

The corresponding CREATE METHOD statement to install the UDM on the server looks like this:

CREATE METHOD toInches()
RETURNS FLOAT
FOR meter
EXTERNAL NAME 'CS!toinches!udm_src/to_inches.c!F!meters_toInches';