All Forums Database
jetfang 2 posts Joined 11/10
08 Sep 2011
UDF Error,[Error 7502] [SQLState HY000

 

hello

,i write a AGGREGATE udf and compile it  to database,but report error when execute it :

Teradata Database] [TeraJDBC 13.00.00.02] [Error 7502] [SQLState HY000] A system trap was caused by UDF/XSP/UDM FW.group_concat for SIGSEGV

does someone can help me ?

Thanks!

this is my code:

------------

REPLACE FUNCTION group_concat(
    Str VARCHAR(255)
)RETURNS   VARCHAR(4000)
CLASS AGGREGATE (4000)
LANGUAGE C
NO SQL
SPECIFIC group_concat
EXTERNAL NAME 'CS!group_concat!c:\\group_concat.c'
PARAMETER STYLE SQL;

-------------

/*
 teradata udf : group_concat
*/
#define MAX_CHAR_LENGTH 64000
#define SQL_TEXT Latin_Text
#include "sqltypes_td.h"
#include <string.h>
#include <stdlib.h>
#define MAX_STRING_LENGTH 6000
#define IsNull -1
#define IsNotNull 0
#define NoSqlError "00000"

 

typedef struct arg_storage {
 SQL_TEXT xCon[4000] ;
} AgrStorage;

void group_concat(FNC_Phase  phase,
     FNC_Context_t *fctx,
     VARCHAR_LATIN   *inputStr,
     VARCHAR_LATIN   *result,
     int   *inputStrIsNull,
     int   *resultIsNull,
     char   sqlstate[6],
     SQL_TEXT  fncname[129],
     SQL_TEXT  sfncname[129],
     SQL_TEXT  errorMsg[257])
{
 AgrStorage *s1 = fctx->interim1 ;
 AgrStorage *s2 = fctx->interim2 ;

 switch (phase) {
 case AGR_INIT:
  if ((s1 = FNC_DefMem(sizeof(AgrStorage))) == NULL) {
   strcpy(sqlstate, "U0001") ;
   //strcpy(errorMsg, "Internal Error: Unable to acquire shared memory from the database.") ;
   return;
  }
  //init s1
  strcpy(s1->xCon,"") ;

 case AGR_DETAIL:
  if (*inputStrIsNull != -1) {
   //concat string.
   strcat(s1->xCon,",");
   strcat(s1->xCon,inputStr);   
  }
  break ;

 case AGR_COMBINE:
  //combine amp
   strcat(s1->xCon,",");
   strcat(s1->xCon,s1->xCon);
  break ;

 case AGR_FINAL:
  //copy to result
  strcpy(result,s1->xCon);
  break ;

 case AGR_NODATA:
  *resultIsNull = -1 ;
  break ;

 default:
  strcpy (sqlstate, "U0005") ;
 }

 return ;
}

 

 

Tags:
You must sign in to leave a comment.