最近项目数据库选型,对于自治事务这个特性,MySQL不支持,在MySQL和PostGreSQL之间权衡对比了一段时间,后来发现,通过UDF可以实现,因此,最终敲定了MySQL,下面来记录下过程:
环境说明:
- 服务器环境: 前面基于CentOS7.1测试,后面基于Windows NT架构的系统进行测试
UDF,也就是user definition function,通过动态库方式实现,因此,我们要做的,就是需要编译出一个动态链接库so或dll。
测试代码如下:
#include
#include
#include
#include
#include
#include
#include
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
#define DLLEXP __declspec(dllexport)
#else
#define DLLEXP
#endif
/* 自定义的函数 */
DLLEXP long long udf_add(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
/* 对应自定义函数的初始化和结束的函数,在调用udf_add函数时由系统调用 */
DLLEXP my_bool udf_add_init(UDF_INIT *initid, UDF_ARGS *args, char