C関数定義 - 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
#define SQL_TEXT Unicode_Text
#include "sqltypes_td.h"
#include <string.h>
#define buffer_size 32000

void dclobdecompress(LOB_LOCATOR*        sourceLobLoc,
                     UDT_HANDLE*         resultUDT,
                     char                sqlstate[6] )
{
   LOB_RESULT_LOCATOR resultLobLoc;
   BYTE inputBuffer[buffer_size];
   BYTE outputBuffer[buffer_size*2];
   LOB_CONTEXT_ID id;
   FNC_LobLength_t readlen, writelen;
   int trunc_err = 0;
   readlen=0;
   writelen=0;

   FNC_GetDistinctResultLob(*resultUDT,&resultLobLoc);
   FNC_LobOpen(*sourceLobLoc, &id, 0, 0);
   while( FNC_LobRead(id, inputBuffer, buffer_size, &readlen) == 0 && !trunc_err )
   {
      int i=0;
      BYTE *inputPtr = inputBuffer;
      BYTE *outputPtr = outputBuffer;
      memset(outputBuffer,0,(buffer_size*2));
      for (i=0; i<readlen; i++)
      {
         memcpy(outputPtr,inputPtr,sizeof(BYTE));
         inputPtr += sizeof(BYTE);
         outputPtr += sizeof(BYTE)*2;
      }
      trunc_err = FNC_LobAppend(resultLobLoc, outputBuffer, readlen*2, &writelen);

      /* check trunc_err and properly report an error (performed in the same way as for
      a standard UDF) */
   }
   FNC_LobClose(id);
}