我有以下cpp代码,它在Netezza中定义一个UDF,它采用某种格式的日期并将其更改为标准的YYYYMMDD格式:
//dateconvert.cpp
#include <stdarg.h>
#include <string.h>
#include "udxinc.h"
#include "udxhelpers.h"
using namespace nz::udx_ver2;
class Dateconvert: public Udf
{
public:
Dateconvert(UdxInit *pInit) : Udf(pInit){}
~Dateconvert(){}
static Udf* instantiate();
virtual ReturnValue evaluate()
{
StringReturn* ret = stringReturnInfo();
StringArg *str;
str = stringArg(0);
int lengths = str->length;
char *datas = str->data;
string data = datas;
data = "'" + data + "'";
string cmd="date -d " + data + " +%Y%m%d 2>/dev/null";
FILE *ls = popen(cmd.c_str(), "r");
char retval[100];
fgets(retval, sizeof(retval), ls);
if(!isdigit(retval[0]))
{
strcpy(retval,"99991231");
}
pclose(ls);
ret->size = sizeof(retval);
memcpy(ret->data, retval, sizeof(retval));
NZ_UDX_RETURN_STRING(ret);
}
};
Udf* Dateconvert::instantiate(UdxInit *pInit)
{
return new Dateconvert(pInit);
}
这是我用来编译/注册UDF的命令:
nzudxcompile /export/home/nz/dateconvert.cpp -o dateconvert.o --sig
"Dateconvert(VARCHAR(200))" --version 2 --return VARCHAR(200)
--class Dateconvert --user user1 --pw password1 --db db1
当我去编译时,我收到错误:
-bash: syntax error near unexpected token `('
在编译c ++程序时,bash如何生成编译错误?即使在消隐cpp文件本身时,错误仍然存在,因此我认为问题在于编译命令。