Accessing the Attribute Values of a Structured UDT | Teradata Vantage - 17.10 - Accessing the Attribute Values of a Structured UDT - 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 attribute values of structured UDTs (including dynamic UDTs), follow these steps:

  1. [Optional] Call FNC_GetStructuredAttributeCount to get the number of attributes in the UDT.
  2. [Optional] Call FNC_GetStructuredAttributeInfo to get information, such as the data type, about the attributes in the UDT.
  3. Access the attribute value based on the data type of the attribute.
    IF the attribute … THEN …
    does not represent a LOB Allocate a buffer using the C data type that maps to the underlying type of the attribute.

    Call FNC_GetStructuredAttribute or FNC_GetStructuredAttributeByNdx to place the value of the attribute into the buffer you allocated.

    represents a LOB Declare a LOB_LOCATOR to hold the locator of the attribute.

    Call FNC_GetStructuredInputLobAttribute or FNC_GetStructuredInputLobAttributeByNdx to set the LOB_LOCATOR to the LOB locator of the attribute.

    Follow the steps in Accessing the Value of a Large Object to read the data.

For details on FNC_GetStructuredAttributeCount, FNC_GetStructuredAttributeInfo, FNC_GetStructuredAttribute, FNC_GetStructuredAttributeByNdx, FNC_GetStructuredInputLobAttribute, and FNC_GetStructuredInputLobAttributeByNdx, see C Library Functions.

Here is a code excerpt that shows how to access the value of a structured type attribute that represents an INTEGER:

void getX( UDT_HANDLE *pointUdt,
           INTEGER    *result,
           char        sqlstate[6])
{
    INTEGER x;
    int nullIndicator;
    int length;
    /* Get the x attribute of pointUdt. */
    FNC_GetStructuredAttribute(*pointUdt, "x", &x, SIZEOF_INTEGER,
                               &nullIndicator, &length);
    if (nullIndicator == -1) {
        /* do null handling here */
        ...
        return;
    }

    ...
}