Setting the Attribute Values of a Structured UDT Result | Teradata Vantage - 17.10 - Setting the Attribute Values of a Structured UDT Result - 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 set the attribute values of a structured UDT that is defined to be the result of a UDF, follow these steps.

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.

Place the value of the attribute into the buffer.

Call FNC_SetStructuredAttribute or FNC_SetStructuredAttributeByNdx to set the value of the attribute to the value in the buffer you allocated.

You can also set the attribute to null.

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

Call FNC_GetStructuredResultLobAttribute or FNC_GetStructuredResultLobAttributeByNdx to set the LOB_RESULT_LOCATOR to the locator of the LOB attribute.

Follow the steps in Appending Data to a Large Object Result to append the return data using the LOB locator.

For details on FNC_SetStructuredAttribute, FNC_SetStructuredAttributeByNdx, FNC_GetStructuredResultLobAttribute, and FNC_GetStructuredResultLobAttributeByNdx, see C Library Functions.

The following code excerpt sets the attribute value of a structured UDT:

void setX( UDT_HANDLE *pointUdt,
           INTEGER    *val,
           UDT_HANDLE *resultPoint,
           char        sqlstate[6])
{
    INTEGER x;
    INTEGER newval;
    int nullIndicator;
    int length;
    /* Set the x attribute of the result point. */
    nullIndicator = 0;
    newval = *val;
    FNC_SetStructuredAttribute(*resultPoint, "x", &newval,
                                nullIndicator, SIZEOF_INTEGER);

    ...
}