16.20 - Example Using FNC_CheckNullBitVector - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
April 2020
Content Type
Programming Reference
Publication ID
B035-1147-162K
Language
English (United States)

In this example, FNC_CheckNullBitVector is called to check the value of element 2 after calling FNC_GetArrayElements.

void VerifyArrayLength ( ARRAY_HANDLE  *ary_handle,
                         char           sqlstate[6])
{
    NullBitVecType *NullBitVector;
    array_info_t arrayInfo;
    long nullVecBufSize;
    int presenceBit;
    bounds_t *arrayRange;
    bounds_t arrayScope[FNC_ARRAYMAXDIMENSIONS];
    index_t lastPresentElement;

    /* Call FNC_GetArrayTypeInfo first to find out the number of */
    /* elements in the array. */
    FNC_GetArrayTypeInfo(*ary_handle,
                         &arrayInfo,
                         arrayScope);
    (arrayInfo.totalNumElements % 8 == 0) ?
       (nullVecBufSize = arrayInfo.totalNumElements / 8) :
       (nullVecBufSize = arrayInfo.totalNumElements / 8) + 1;

    /* Allocate a new NullBitVector array. */
    NullBitVector = (NullBitVecType*)FNC_malloc(nullVecBufSize);

    /* Initialize the NullBitVector to default values. */
    memset(NullBitVector, 0, nullVecBufSize);
    arrayRange =
    (bounds_t*)FNC_malloc(sizeof(bounds_t)*arrayInfo.numDimensions);

    /* Set values of arrayRange to correspond to the range [1:2][1:2] */
    arrayRange[0].lowerBound = 1;
    arrayRange[0].upperBound = 2;
    arrayRange[1].lowerBound = 1;
    arrayRange[1].upperBound = 2;

    /* Get elements within the range [1:2][1:2] of myArray. */
    FNC_GetArrayElements(*ary_handle, arrayRange, &result, buffer,
       NullBitVector, &length);

    /* Check the presence bit for element [1][1] */
    presenceBit = FNC_CheckNullBitVector(NullBitVector, 1,
       nullVecBufSize);
    ...
}