Accessing the Attribute Values of a Structured UDT | Teradata Vantage - Accessing the Attribute Values of a Structured UDT - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
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;
    }

    ...
}