16.20 - C Function Definition That Uses 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 maps the GLOP set and then reads the GLOP data.

/********** File: glop_map1.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

/*************************************************************/
/* Function to read GLOP data for the given record_n number. */
/*************************************************************/

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

struct Company_Info
{
  struct Company Dept[LOOPSIZE];
}*COMPANY_DETAILS;

void glop_map1( INTEGER *record_n,
                VARCHAR_LATIN *Deptname1,
                INTEGER *record_nIsNull,
                INTEGER *Deptname1IsNull,
                char sqlstate[6],
                SQL_TEXT extname[129],
                SQL_TEXT specific_name[129],
                SQL_TEXT error_message[257] )
{

   int glop_stat, MAP_ADD;
   int i;
   GLOP_Map_t *MyGLOP;

   if (*record_nIsNull == IsNull)
   {
      strcpy(sqlstate, "22004") ;
      strcpy((char *) error_message, "Null value not allowed.") ;
      *Deptname1IsNull = IsNull;
      return;
   }

   strcpy((char *) error_message, " ");
   *Deptname1IsNull = IsNotNull;

   MAP_ADD = 0; // Use the first GLOP section of the GLOP set.
   i = *record_n;
   glop_stat = FNC_Get_GLOP_Map(&MyGLOP);

   // Check whether mapping is established or not

   if (glop_stat)
   {
      if (glop_stat == -1)
         strcpy((char*)error_message,
            "Map not set up. Exceeded GLOP data mapping limits.");
      else if (glop_stat == -2)
         strcpy((char*)error_message,
            "Not member of GLOP set or no rows in GLOP tables.");
      strcpy(sqlstate,"U0001");
      return;
   }

   // Check whether specified row for the GLOP exists or not

   if (MyGLOP->GLOP[MAP_ADD].GLOP_ptr == NULL)
   {
      strcpy((char*)error_message,"Map does not exist at index 0.");
      strcpy(sqlstate,"U0002");
      return;
   }

   if (MyGLOP->GLOP[MAP_ADD].size == 0)
   {
      strcpy((char*)error_message,"Nothing is mapped.");
      strcpy(sqlstate,"22023");
      return;
   }

   // Assign the mapped address of GLOP data to the structure.

   COMPANY_DETAILS = MyGLOP->GLOP[MAP_ADD].GLOP_ptr;

   // Read the data.
   strcpy(Deptname1,COMPANY_DETAILS->Dept[i].deptname);

}