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

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)
#define BUFFER_SIZE 500

/* Aggregate intermediate record */
typedef struct
{
   FNC_LobLength_t length;
   LOB_REF         ref;
   BYTE            prefix[BUFFER_SIZE];
} 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 actsize;

   switch (phase)
   {
   case AGR_INIT:
      s1 = (intrec_t *)FNC_DefMem(sizeof(intrec_t));
      s1->length = FNC_GetLobLength(*x);
      FNC_LobOpen(*x, &id, 0, BUFFER_SIZE);
      FNC_LobRead(id, s1->prefix, BUFFER_SIZE, &actsize);
      FNC_LobClose(id);

      /* if the object length is less than the size
         allotted, pad the remaining bytes with zeros. */
      while (actsize < BUFFER_SIZE)
         s1->prefix[actsize++] = 0;
       FNC_LobLoc2Ref(*x, &s1->ref); 

   case AGR_DETAIL:

      ...

      break;

   ...

}

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