网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库 > MySQL教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
本月文章推荐
.MySQL与Access之语法区别.
.案例:MySQL服务无法启动 系统发.
.教你快速掌握MySQL数据库的双向加.
.mysql常识和基本操作.
.有了MySQL,客户资源管理尽在掌握.
.MySQL的存储过程写法和"Cursor"的.
.MySQL数据库中如何解决分组统计的.
.MySQL数据库和备份与恢复.
.SQL Server 7.0 的数据迁移到MyS.
.如何将MySQL数据库迁移到Oracle数.
.MYSQL用户root密码为弱口令的攻击.
.MySQL 5.0新特性教程 存储过程:第.
.MySQL安全性指南 (2)(转).
.从一个MysqL的例子来学习查询语句.
.为新安装的RHEL AS设定MySQL初始.
.mysql存储过程及c#调用标准版.
.教你在MySQL中快速复制表格作为测.
.初学者在使用MySQL时必须了解的注.
.怎样使MySQL安全以对抗解密高手.
.谈谈数据从sql server数据库导入.

Windows上的MySQL UDF开发

发表日期:2003-5-20


曾以为Windows版本的MySQL存在不能使用UDF的BUG诸提交了一个bug报告。不过
似乎发现是我搞错了,MySQL的技术支持人员给了非常完美的解答,同大家分享
一下。下边是原文回复 :)

Sorry this isn't a bug.
Below I pasted a sample I did sometime ago for another user:

Ok. Assuming you have VC++ and the source distribution and a server
running,
I will create a UDF that returns a name:

Note: the sample is ugly, but the purpose here is to show you how
to handle the UDF.

- Open the mysqld.dsw workspace.
- Add New project to the workspace
- Project name: my_udf
- Select Win32 Dynamic-Link Library
- Click OK
- Select An Empty DLL project
- Click Finish
- Click OK
- Add a new file called my_udf.cpp to the project:

#include <stdlib.h>
#include <winsock.h>
#include <mysql.h>

extern "C" {
char *my_name(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
       char *error);
}

char *my_name(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
       char *error)
{
    char * me = "my name";

    return me;
}

- Type Ctrl+N for to create a new file.
- Select text type
- File name: my_udf.def
- Edit the above file with the below contents:
LIBRARY         UDF_EXAMPLE
DESCRIPTION             'Example Using UDF with VC++'
VERSION         1.0
EXPORTS
        my_name

- Right Click the my_udf project and select Settings
- Click the C/C++ tab
- Select General in the Category Combo
- Add the macro HAVE_DLOPEN to the PreProcessor definition
- Select Preprocessor in the Category Combo
- Add the include path to the text box: Additional Include directories
  e.g: ../include
- Press F7 for to build the DLL.

- Copy the my_udf.dll to the environment path directory:
  \winnt\system32 for example.

- Start the mysql client and issue:

C:\mysql-udf\bin>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 3.23.52-max-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE FUNCTION my_name RETURNS STRING SONAME "my_udf.dll";
Query OK, 0 rows affected (0.08 sec)

mysql> select my_name();

mysql> drop function my_name;
Query OK, 0 rows affected (0.00 sec)

画蛇添足的作下简要中文说明。

抱歉,这并不是一个bug。下面我粘贴一个以前为某个客户做的简例,假设你有了
VC++,源码分发,并且有一个正常运行的MySQL服务器。

我将创建一个UDF它将一个名字:
注意:例子非常简陋,目的是让你了解该如何处理手头的UDF。

- 打开 mysqld.dsw 工作区。
- 添加新项目到这个工作区
- Project name: my_udf            // 项目名称:my_udf
- 选择 Win32 Dynamic-Link Library // Win32动态连接库
- 点击 OK
- 选择 An Empty DLL project       // 一个空DLL项目
- 点击 Finish
- 点击 OK
- 添加新文件 my_udf.cpp 到项目中:
#include <stdlib.h>
#include <winsock.h>
#include <mysql.h>

extern "C" {
char *my_name(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
       char *error);
// 兼容C
}

char *my_name(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
       char *error)
{
    char * me = "my name";

    return me;
    // 调用此UDF将返回 my name
}
- 按 Ctrl+N 来创建一个新文件。
- 选择 text 类型
- File name: my_udf.def file://文件名:my_udf.def
- 按照下边的内容编辑文件。
LIBRARY         UDF_EXAMPLE
DESCRIPTION             'Example Using UDF with VC++'
VERSION         1.0
EXPORTS
        my_name

- 右击my_udf项目并选择Settings
- 点 C/C++ 选项卡
- 选择 General
- 添加宏 HAVE_DLOPE 到预处理器定义
- 选择 Preprocessor
- 添加头文件路径: Additional Include directories
  例如: ../include
- 按 F7 去编译成 DLL.

- 复制 my_udf.dll 到环境变量path定义过的目录
  比如 \winnt\system32 。

- 打开mysql客户端

C:\mysql-udf\bin>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 3.23.52-max-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE FUNCTION my_name RETURNS STRING SONAME "my_udf.dll";
Query OK, 0 rows affected (0.08 sec)

mysql> select my_name();

mysql> drop function my_name;
Query OK, 0 rows affected (0.00 sec)


ok!欢迎大家来MySQL板交流UDF设计经验!我的电子邮件是HeartIcy@163.com
手机13706410308。同时,我们MySQL板准备开始系统化持续性翻译MySQL文档,
希望大家多多支持共同完成这一项目。

HeartIcy
2003年5月17日于中国济南

上一篇:选择MySQL还是SQL Server 人气:35646
下一篇:Mysql数据库的安全配置、实用技巧 人气:21488
浏览全部MySQL的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐