C Function Definition for the Ordering Method - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
rin1593638965306.ditamap
dita:ditavalPath
rin1593638965306.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantageā„¢

The following example implements ordering functionality that allows Vantage to order two circle_t UDTs by their area. The function gets the radius and computes the area, returning the result as a FLOAT data type. If the circle is null or if the x attribute, y attribute, or radius attribute of the circle is null, the function returns a null result.

/* File: c_order.c */

#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>

void circle_t_Ordering( UDT_HANDLE *circleUdt,
                        FLOAT      *result,
                        int        *indicator_circle,
                        int        *indicator_result,
                        char       sqlstate[6],
                        SQL_TEXT   extname[129],
                        SQL_TEXT   specific_name[129],
                        SQL_TEXT   error_message[257])
{
    INTEGER x, y, r;
    int nullIndicator;
    int length;

    /* If circle is null, return null. */
    if (*indicator_circle == -1) {
        *indicator_result = -1;
        return;
    }

    /* Verify that the x attribute is not null. */
    FNC_GetStructuredAttribute(*circleUdt, "x", &x, SIZEOF_INTEGER, &nullIndicator, &length);
    if (nullIndicator == -1) {
        *indicator_result = -1;
        return;
    }

    /* Verify that the y attribute is not null. */
    FNC_GetStructuredAttribute(*circleUdt, "y", &y, SIZEOF_INTEGER, &nullIndicator, &length);
    if (nullIndicator == -1) {
        *indicator_result = -1;
        return;
    }

    /* Get the radius attribute. */
    FNC_GetStructuredAttribute(*circleUdt, "radius", &r, SIZEOF_INTEGER, &nullIndicator, &length);
    if (nullIndicator == -1) {
        *indicator_result = -1;
        return;
    }

    *result = 3.14 * r * r;

}