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; }