17.10 - Example Using FNC_LobOpen_CL - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Advanced SQL Engine
Teradata Database
Release Number
Release Date
July 2021
Content Type
Programming Reference
Publication ID
English (United States)

The following code reads a LOB from the input stream and copies its content into the output stream.

int                  streamno=0;
int                  i;
BYTE                 *locator;
int                  locatorLength;
int                  null_ind;
FNC_LobLength_t      lobLength;
LOB_CONTEXT_ID       lobid;
BYTE                 Buffer[BufferSize];
int                  length;
int                  truncerr;
FNC_TblOpHandle_t    *Handle, *OutHandle;

   // Get locator for LOB in column  i  of output stream  streamno 
   lrl_a = FNC_LobCol2Loc(streamno, i);
   // Get client locator for input LOB
   FNC_TblOpGetAttributeByNdx(Handle, i, (void **) &locator, &null_ind, &locatorLength);
   if (null_ind != -1) {
      // Open input LOB
      FNC_LobOpen_CL(locator, &lobid, 0, 0);
      truncerr = 0;
      // Read input LOB and append it to output LOB
      while( FNC_LobRead(lobid, Buffer, BufferSize, &length) == 0 && !truncerr)
         truncerr=FNC_LobAppend (lrl_a, Buffer, length, &actlen);
         // Close input LOB
      // Set output column to NULL
      FNC_TblOpBindAttributeByNdx(OutHandle, i, locator, null_ind, locatorLength);