FNC_GetArrayElementsの使用例 - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL外部ルーチン プログラミング

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
2020年6月
Language
日本語
Last Update
2021-03-30
dita:mapPath
ja-JP/qwr1571437338192.ditamap
dita:ditavalPath
ja-JP/qwr1571437338192.ditaval
dita:id
B035-1147
Product Category
Software
Teradata Vantage

この例は、次のn-D ARRAY定義に基づいています。

/*Oracle-compatible and Teradata syntax respectively: */
CREATE TYPE myArray AS VARRAY(1:20)(1:20) OF integer;
CREATE TYPE myArray AS integer ARRAY[1:20][1:20];

/*This function returns a range of element values */
void getMultiElement ( ARRAY_HANDLE  *ary_handle,
                       void          *result,
                       char           sqlstate[6])
{
    long length;
    long bufferSize = sizeof_integer * 4;
    int *resultBuf;
    NullBitVecType    *NullBitVector;
    array_info_t arrayInfo;
    int totalElements;
    long nullVecBufSize;
    bounds_t *arrayRange;
    bounds_t arrayScope[FNC_ARRAYMAXDIMENSIONS];

    /* Call FNC_GetArrayTypeInfo first to find out the number of */
    /* elements in the array. */
    FNC_GetArrayTypeInfo(*ary_handle,
                         &arrayInfo,
                         arrayScope);
    nullVecBufSize = arrayInfo.totalNumElements;

    resultBuf = (int*)FNC_malloc(bufferSize);

    arrayRange =
    (bounds_t*)FNC_malloc(sizeof(bounds_t)*arrayInfo.numDimensions);

    /* Allocate a new NullBitVector to pass to FNC_GetArrayElements */
    NullBitVector = (NullBitVecType*)FNC_malloc(nullVecBufSize);

    /* Set all members of NullBitVector to 0 */
    memset(NullBitVector, 0, nullVecBufSize);

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

    /* Get elements within the range [1:2][2:3] of myArray. */
    FNC_GetArrayElements(*ary_handle, &arrayRange, resultBuf,
       bufferSize, NullBitVector, NullVecBufSize, &length);
}

この例は、resultBufに格納された4つの整数の配列を返します。この4つの値は次のとおりです。

10 12 20 33

これらの値は、整数値としてresultBufの該当するエントリを取得することで直接アクセスできます。