16.20 - Example Using FNC_LobRef2Loc - 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)
#define BUFFER_SIZE 10000

/* Aggregate intermediate record */
typedef struct
{
   FNC_LobLength_t length;
   LOB_REF         ref;
   BYTE            prefix[500];
} intrec_t;

void Max_Blob(FNC_Phase          phase,
              FNC_Context_t      *fctx,
              LOB_LOCATOR        *x,
              LOB_RESULT_LOCATOR *result,
              int                *x_i,
              int                *result_i,
              char               sqlstate[6])
{
   intrec_t        *s1 = (intrec_t*) fctx->interim1;
   LOB_CONTEXT_ID  id;
   FNC_LobLength_t actlen;

   switch (phase)
   {
   case AGR_INIT:

      ...

   case AGR_DETAIL:

      ...

      break;
   case AGR_FINAL:
      FNC_LobOpen(*(FNC_LobRef2Loc(&s1->ref)), &id, 0, 0); 
      FNC_LobRead(id, buffer, BUFFER_SIZE, &actlen);
      FNC_LobAppend(*result, buffer, actlen, &actlen);
      FNC_LobClose(id);
      break;

   ...

}

For a complete example that uses FNC_LobRef2Loc, see C Aggregate Function Using LOBs .