首頁 資料庫 mysql教程 在Windows上的MySQL UDF开发应用_MySQL

在Windows上的MySQL UDF开发应用_MySQL

Jun 01, 2016 pm 02:11 PM
char the 應用 開發


  曾以为Windows版本的MySQL存在不能使用UDF的BUG诸提交了一个bug报告。不过似乎发现是我搞错了,MySQL的技术支持人员给了非常完美的解答,同大家分享一下。下边是原文回复。
  
  用户你好。抱歉,这并不是一个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
  
  #include
  
  #include
  
  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)
  
  以下是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
  
  #include
  
  #include
  
  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)
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

PHP中箭頭符號的作用及實作應用 PHP中箭頭符號的作用及實作應用 Mar 22, 2024 am 11:30 AM

PHP中箭頭符號的作用及實作應用

四款值得推薦的AI輔助程式工具 四款值得推薦的AI輔助程式工具 Apr 22, 2024 pm 05:34 PM

四款值得推薦的AI輔助程式工具

如何在iPhone中撤銷從主畫面中刪除 如何在iPhone中撤銷從主畫面中刪除 Apr 17, 2024 pm 07:37 PM

如何在iPhone中撤銷從主畫面中刪除

AI程式設計師哪家強?探索Devin、通靈靈碼和SWE-agent的潛力 AI程式設計師哪家強?探索Devin、通靈靈碼和SWE-agent的潛力 Apr 07, 2024 am 09:10 AM

AI程式設計師哪家強?探索Devin、通靈靈碼和SWE-agent的潛力

學習如何利用Go語言開發行動應用程式 學習如何利用Go語言開發行動應用程式 Mar 28, 2024 pm 10:00 PM

學習如何利用Go語言開發行動應用程式

2 個月不見,人形機器人 Walker S 會摺衣服了 2 個月不見,人形機器人 Walker S 會摺衣服了 Apr 03, 2024 am 08:01 AM

2 個月不見,人形機器人 Walker S 會摺衣服了

從入門到精通:探索Linux tee命令的各種應用場景 從入門到精通:探索Linux tee命令的各種應用場景 Mar 20, 2024 am 10:00 AM

從入門到精通:探索Linux tee命令的各種應用場景

了解VSCode:這款工具到底是用來做什麼的? 了解VSCode:這款工具到底是用來做什麼的? Mar 25, 2024 pm 03:06 PM

了解VSCode:這款工具到底是用來做什麼的?

See all articles