我正在用C编写我的第一个用户定义函数,该函数将从mysql调用。代码很简单:
char *getKey(UDF_INIT *initid __attribute__((unused)),
UDF_ARGS *args, char *result, unsigned long *length,
char *is_null, char *error __attribute__((unused)))
{
const char *word=args->args[0];
strcpy(result,"EOOOOOOOO");
return result;
}
我已经编译并加载它没有问题。
CREATE FUNCTION getKey RETURNS STRING SONAME 'udf_key.so';
为了测试它,我在一个插入查询中调用它:
INSERT INTO `seed4c`.`users` (`iduser`,`userscol`) VALUES (1,getkey('aa'));
userscol是Varchar(45),因此返回的字符串应该有足够的空间。我收到警告
1 row(s) affected, 1 warning(s): 1265 Data truncated for column 'userscol' at row 1
在表中进行“选择”时,该字段具有预期值(EOOOOOOOO)和一些奇怪的字符(非字母数字)。
我究竟做错了什么?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句