17.10 - C Function Definition - 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 SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>
#define buffer_size 100000
const char trunc_err[6] = "22001";
static int append_lob(LOB_RESULT_LOCATOR, LOB_LOCATOR);
void concat3( LOB_LOCATOR         *a,
              VARBYTE             *b,
              LOB_LOCATOR         *c,
              LOB_RESULT_LOCATOR  *result,
              char                sqlstate[6] )
{
   FNC_LobLength_t actlen;
   /* Append the first argument. Note that a truncation error could
      occur only if the result exceeds the maximum LOB size, so the
      first append should never get that error.
    */
   if (append_lob(*result, *a) != 0)
   {
      strcpy(sqlstate, trunc_err);
      return;
   }
   /* Append the second argument */
   if (FNC_LobAppend(*result, b->bytes, b->length, &actlen) != 0)
   {
      strcpy(sqlstate, trunc_err);
      return;
   }
   /* Append the third argument */
   if (append_lob(*result, *c) != 0)
   {
      strcpy(sqlstate, trunc_err);
      return;
   }
}
int append_lob( LOB_RESULT_LOCATOR dest,
                LOB_LOCATOR source )
{
   BYTE buffer[buffer_size];
   LOB_CONTEXT_ID id;
   FNC_LobLength_t actlen;
   int trunc_err = 0;
   FNC_LobOpen(source, &id, 0, 0);
   while( FNC_LobRead(id, buffer, buffer_size, &actlen) == 0 &&
            !trunc_err )
      trunc_err = FNC_LobAppend(dest, buffer, actlen, &actlen);
   FNC_LobClose(id);
   return trunc_err;
}