Accessing the Attribute Values of a Structured UDT | Teradata Vantage - Accessing the Attribute Values of a Structured UDT - 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™

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

    ...
}