17.10 - Accessing the Value of a Period Argument - 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)

To access the value of a Period type argument, follow these steps:

  1. Allocate a buffer that is large enough to hold the beginning and ending bounds of the Period type, as represented by the C data type that maps to the SQL element type.

    For example, consider a CREATE FUNCTION statement that specifies a PERIOD(TIME WITH TIME ZONE) argument. To access the value of the argument, the function must allocate a buffer that is large enough to hold two ANSI_Time_WZone values, where ANSI_Time_WZone is the C data type that maps to TIME WITH TIME ZONE.

  2. Call FNC_GetInternalValue to place the value of the Period type into the buffer you allocated.

For detailed information on FNC_GetInternalValue, see C Library Functions

Here is a code excerpt that shows how to access the value of a PERIOD(DATE) type:

void check_duration( PDT_HANDLE    *duration,
                     INTEGER       *result,
                     char           sqlstate[6])
{
    void * tmpBuf = 0;
    int bufSize = 0;
    int length;
    /* Get the value of the PERIOD(DATE) duration. */
    bufSize = SIZEOF_DATE * 2;
    tmpBuf = FNC_malloc(bufSize);
    FNC_GetInternalValue(*duration, tmpBuf, bufSize, &length);
    ...
}