16.20 - C Function Definition That Generates GLOP Data - 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)

This function generates GLOP data that is added to a GLOP set as a system type GLOP.

/********** File: compinform.c **********/

#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>
#include <stdlib.h>
#define IsNull -1
#define IsNotNull 0
#define loopsize  20

/**************************************************************/
/* Generate data for different departments in a retail store. */
/**************************************************************/

struct Company
{
   INTEGER deptid;
   char deptname[30];
};

struct Company_INFO
{
   struct Company Dept[loopsize];
}*COMPANY_DETAILS;


void compinform( LOB_RESULT_LOCATOR *cmp_info,
                 INTEGER *cmp_infoISNULL,
                 char sqlstate[6],
                 SQL_TEXT extname[129],
                 SQL_TEXT specific_name[129],
                 SQL_TEXT error_message[257] )
{

   FNC_LobLength_t actlen;
   int i;
   const char truncate1a[6] = "22001";
   char *Dept_Name[20] =
      {"Automotive", "Hardware", "Bed", "Bath", "Toys", "Food",
       "Electronics", "Games", "Photo", "Kitchen", "Seasonal", "Books",
       "Furniture", "Pharmacy", "Men", "Women", "Baby", "Kids",
       "Shoes", "Nursery"};

   // Allocate memory to store the contents.

   COMPANY_DETAILS =
      (struct Company_INFO *)FNC_malloc(sizeof(struct Company_INFO));

   // Store data in a structure format.

   for (i=0; i<loopsize; i++)
   {
      COMPANY_DETAILS->Dept[i].deptid=i+1;
      strcpy(COMPANY_DETAILS->Dept[i].deptname,(char*)Dept_Name[i]);
   }

   // Add data to BLOB.

   if (FNC_LobAppend(*cmp_info,COMPANY_DETAILS,
                     sizeof(*COMPANY_DETAILS),& actlen) !=0)
   {
      strcpy(sqlstate, truncate1a);
      FNC_free(COMPANY_DETAILS);
      return;
   }

   // Free the memory that was allocated to the structure CompanyName.

   FNC_free(COMPANY_DETAILS);
}