17.00 - 17.05 - C関数定義 - Advanced SQL Engine - Teradata Database

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

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
17.05
Published
2020年6月
Content Type
プログラミング リファレンス
Publication ID
B035-1147-170K-JPN
Language
日本語 (日本)
/* function context area */
typedef struct arg_storage {
   int  MaxOfColumn ;
} AgrStorage ;

void AggFncWAnytype(
   FNC_Phase       phase,
   FNC_Context_t  *fContext,
   void           *input,
   INTEGER        *result,
   int            *inputIsNull,
   int            *resultIsNull,
   char            sqlstate[6],
   SQL_TEXT        extname[129],
   SQL_TEXT        specific_name[129],
   SQL_TEXT        error_message[257] )

{
   int                   sumValue = 0;
   anytype_param_info_t  paraminfo;
   int                   numAnyType;

   AgrStorage *s1 = fContext->interim1 ;
   AgrStorage *s2 = fContext->interim2 ;

   switch (phase)
   {
      case AGR_INIT:
         /* Allocate and initialize the intermediate storage. */
         if ((s1 = FNC_DefMem(sizeof(AgrStorage))) == NULL) {
            strcpy((char *)sqlstate, "U09999") ;
            strcpy((char *)&(error_message[0]),"Memory allocation failure");
            return;
         }

         s1->MaxOfColumn = 0;
         strcpy((char *)sqlstate, "00000");
         memset(&(error_message[0]), 0, sizeof(error_message));

      case AGR_DETAIL:
         FNC_GetAnyTypeParamInfo( sizeof(anytype_param_info_t), &numAnyType, &paraminfo);

         /* Process the value based upon the data type. */
         switch(paraminfo.datatype)
         {
            case BYTEINT_DT:
            case SMALLINT_DT:
            case INTEGER_DT:
               /* Process the value */
               s1->MaxOfColumn = 10;
               break;
            case VARCHAR_DT:
            case CHAR_DT:
               s1->MaxOfColumn = 11;
               break;
            case CLOB_REFERENCE_DT:
               s1->MaxOfColumn = 12;
               break;
            default:
               /* Invalid string */
               strcpy((char *)sqlstate, "22023");
               sprintf((char*)error_message, "\n Invalid Data Type passed into UDF");
               break;
         } /* end of the switch statement */
         break;

      case AGR_COMBINE:
         /* combine the intermediate results */
         if(s1->MaxOfColumn < s2->MaxOfColumn)
            s1->MaxOfColumn =s2->MaxOfColumn;
         break;

      case AGR_FINAL:
         /* produce the final result */
         *result = s1->MaxOfColumn;
         break;

      case AGR_NODATA:
         /* No data passed in ... so nothing to do */
         //Indicate that OUTPUT is being produced.
         *resultIsNull =IsNull;
         break;

      default:
         strcpy (sqlstate, "U0005") ;
         sprintf((char*)error_message,"\n Unknown Aggregate Phase!");
         return;
   }
}