linux下mysql扩展,自定义函数实现(…
来源:互联网 发布:男士服装搭配软件 编辑:程序博客网 时间:2024/06/03 21:29
Adding a New User-DefinedFunction
"The MySQL source distribution includes a filesql/udf_example.c
that defines 5 new functions"下载mysql在目录中可看到sql/udf_example.c,我们可以参考。
流程:编译自己的动态库=>创建函数
首先建立一个简单的测试函数库,返回值为字符串类型
代码为:
//mtest.h
#ifndef MTEST_H_
#define MTEST_H_
#include <my_global.h>
#include <mysql.h>
my_bool mtest_init(UDF_INIT *initid, UDF_ARGS *args, char*message);
char *mtest(UDF_INIT *initid, UDF_ARGS *args,
void mtest_deinit(UDF_INIT *initid);
#endif
//mtest.c
#include <string.h>
#include "mtest.h"
my_bool mtest_init(UDF_INIT *initid, UDF_ARGS *args, char*message)
{
if(0 != args->arg_count){
strncpy(message, "mtest has no arguments", strlen("mtest hasno arguments") + 1);
return 1;
}
initid->ptr = calloc(1, 1024);
return 0;
}
char *mtest(UDF_INIT *initid, UDF_ARGS *args,
{
char *ps = "mysql plugin string type test.";
*length = strlen(ps);
memcpy(initid->ptr, ps, *length + 1);
return initid->ptr;
}
void mtest_deinit(UDF_INIT *initid)
{
free(initid->ptr);
}
编译为libmtest.so,复制到plugin目录下
重启mysql
$mysql -h127.0.0.1 -u root -P3306
//create
mysql> CREATE FUNCTION mtest RETURNS STRINGSONAME 'libmtest.so';
mysql> select mtest();
+--------------------------------+
| mtest() |
+--------------------------------+
| mysql plugin string type test. |
+--------------------------------+
1 row in set (0.02 sec)
//drop
mysql> DROP FUNCTION mtest;
- linux下mysql扩展,自定义函数实现(…
- Linux平台下 MYSQL用户自定义函数(UDF)的利用
- 扩展JMeter实现自定义的函数
- linux下php开发自定义扩展库
- Linux下安装mysql和curl扩展
- Linux下php安装mysql扩展
- CentOS(Linux)下php添加mysql扩展
- linux下python安装Mysql扩展
- linux下python安装Mysql扩展
- hive 自定义函数扩展
- linux下安装mysql以及php的mysql扩展
- linux下使用Eclipse创建mysql UDF(用户自定义函数)
- MySQL自定义函数的Windows版本实现
- mysql利用自定义变量实现分析函数
- mysql自定义函数实现递归查询
- linux下运行strlwr函数的自定义
- mysql-concat扩展函数
- Linux下实现getch()函数
- 文件锁File Locking示例
- Beej's Quick Guide to GDB
- 简单socket服务器客户端
- hdu 3905 Sleeping
- 使用事件驱动模型实现高效稳定的网…
- linux下mysql扩展,自定义函数实现(…
- 系统信号表格和一些资料
- 数据机构快速排序之c语言实现
- 线性插值原理
- epoll监听pipe,fork后父进程写给…
- System V 信号量操作,进程间通信(…
- System V 信号量操作,进程间通信(…
- 我的博客今天1岁352天了,我领取了…
- 将博客搬至CSDN