C Function Definition for the Ordering Method - 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ā„¢

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;

}