MySQL:如何编写UDF(8)

来源:未知 责任编辑:责任编辑 发表时间:2013-11-15 19:51 点击:

  

    *total = 0; 

    initid->ptr = (char *)total; 

  

    if (args->arg_count != 1){            //检查参数个数 

        strcpy(message, "too moreargs,only one!"); 

        return 1; 

    } 

  

    if (args->arg_type[0] != REAL_RESULT){  //检查参数类型 

        strcpy(message, "wrongtype"); 

        return 1; 

    } 

  

    initid->decimals = 3;         //设置返回值精度 

    return 0; 

 

 

 

//清理、释放在init函数中分配的内存

 

voidudf_floatsum_deinit(UDF_INIT *initid) 

    free(initid->ptr); 

 

 

 

//每一行都会调用到该函数

 

voidudf_floatsum_add(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) 

    double* float_total; 

    float_total = (double*)initid->ptr; 

  

    if (args->args[0]) 

        *float_total += *(double*)args->args[0]; 

  

 

 

 

//每个分组完成后,返回结果

 

doubleudf_floatsum(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) 

    double* float_total; 

    float_total = (double *)initid->ptr; 

    return *float_total; 

 

 

 

//在进行下一个分组前调用,设置initid->ptr指向的值为0,以便下一次分组统计

 

voidudf_floatsum_clear(UDF_INIT *initid, char *is_null, char *error) 

    double *float_total; 

    float_total = (double *)initid->ptr; 

    *float_total = 0; 

  

 

 

3) Mysql-udf-http是一个开源的UDF,可以利用HTTP协议进行REST操作。什么是REST操作呢?REST是一种web service架构风格,其实现基于HTTP协议的四种方法:POST、GET、PUT以及DELETE操作,在mysql-udf-http里分别对应的函数是http_post、http_get()、http_put()、http_delete()。

源码下载:http://curl.haxx.se/download/curl-7.21.1.tar.gz

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • mysql-mmm
  • mysqldump命令——MySQL数据库备份还原
  • Oracle数据导入MySQL的快捷工具:MySQL Migration Toolkit
  • 简简单单储存过程——循环一个select结果集
  • MySQL数据库十大优化技巧
  • Mysql主主复制架构配置
  • Mysql安装笔记
  • MySQL Stmt预处理提高效率问题的小研究
  • Mysql的Procedure 参数为NULL问题分析
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1