最近项目数据库选型,对于自治事务这个特性,MySQL不支持,在MySQL和PostGreSQL之间权衡对比了一段时间,后来发现,通过UDF可以实现,因此,最终敲定了MySQL,下面来记录下过程:
环境说明:
- 服务器环境: 前面基于CentOS7.1测试,后面基于Windows NT架构的系统进行测试
- 数据库环境: MYSQL5.7.19
UDF,也就是user definition function,通过动态库方式实现,因此,我们要做的,就是需要编译出一个动态链接库so或dll。
测试代码如下:
#include <my_global.h>
#include <my_sys.h>
#include <mysql.h>
#include <m_ctype.h>
#include <m_string.h>
#include <stdlib.h>
#include <ctype.h>
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
#define DLLEXP __declspec(dllexport)
#else
#define DLLEXP
#endif
/* 自定义的函