17.10 - Allocating the returnValue Buffer - 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)

Before calling FNC_GetArrayElements, you must allocate the buffer pointed to by returnValue using the C data type that maps to the underlying type of the element. Be sure to allocate the buffer for the number of elements which has been requested. For example, if the underlying type of the element is an SQL INTEGER data type, declare the buffer like this:

INTEGER value;

If the element type is a distinct type, allocate a buffer using the C data type that the distinct type represents. For example, if the element is a distinct type that represents an SQL SMALLINT data type, declare the buffer like this:

SMALLINT value;

If the underlying type of the element is a character string, FNC_GetArrayElements returns a null-terminated character string. The buffer you define must be large enough to accommodate null termination.

If the element type is a structured type, FNC_GetArrayElements returns a UDT handle. To get descriptive information on the attributes of the structured type, pass the UDT handle to FNC_GetStructuredAttributeInfo. For more information, see FNC_GetStructuredAttributeInfo [Deprecated].

To guarantee that the value you pass in for the returnValueBufSize argument matches the length of the data type, use the data type length macros defined in sqltypes_td.h. For UDT element types, use the macro SIZEOF_UDT_HANDLE in calculating the total size of the returnValue buffer since UDT handles are returned. For a list of the data type length macros, see FNC_GetStructuredAttribute.

Be sure to release allocated resources once you have processed the data.