C関数定義 - Teradata Database - Teradata Vantage NewSQL Engine

Teradata Vantage™ SQL外部ルーチン プログラミング

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
2019年3月
Language
日本語
Last Update
2019-10-29
dita:mapPath
ja-JP/uhh1512082756414.ditamap
dita:ditavalPath
ja-JP/uhh1512082756414.ditaval
dita:id
B035-1147
Product Category
Software
Teradata Vantage
#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;
}