在Windows上的MySQL UDF开发应用

2016-02-19 14:43 87 1 收藏

只要你有一台电脑或者手机,都能关注图老师为大家精心推荐的在Windows上的MySQL UDF开发应用,手机电脑控们准备好了吗?一起看过来吧!

【 tulaoshi.com - 编程语言 】

曾以为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定义过的目录
  
  比如 winntsystem32 。
  
  - 打开mysql客户端
  
  C:mysql-udfinmysql -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 serverrunning,
  
  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:
  
  winntsystem32 for example.
  
  - Start the mysql client and issue:
  
  C:mysql-udfinmysql -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)

来源:https://www.tulaoshi.com/n/20160219/1607715.html

延伸阅读
标签: Web开发
AJAX无疑是2005年炒的最热的Web开发技术之一,当然,这个功劳离不开Google。我只是一个普通开发者,使用AJAX的地方不是特别多,我就简单的把我使用的心得说一下。(本文假设用户已经具有JavaScript、HTML、CSS等基本的Web开发能力) [AJAX介绍] Ajax是使用客户端脚本与Web服务器交换数据的Web应用开发方法。Web页面不用打断交互流程进行重新...
标签: PHP
我们可以使用PHP来编写WAP程序,比如开发动态的WML页面,不过条件是需要将输出的标签或语句限制在WAP微型浏览器可接受的范围之内。而且,PHP 还可以在一个HTML(及HDML)文件中编写出既适合于HTML(及HDML),也适合于WML的内容。PHP的源代码对于WAP客户端来说是不可见的,所以我们可以针对HTML浏览器输出HTML页面,而针对WAP浏览器...
标签: 电脑 网络
一、Mac上运行Windows的方法 1、最常见的解决方案是使用Boot Camp。 它是包含在OS X所有版本的免费工具,它可以让你在Mac上安装Windows的旁边OS X的一个副本 2、使用Boot Camp安装Windows的过程是直接的,但不是我想大多数消费者将能够做到,除非他们有技术背景。 如果你有在Windows CD / DVD,这使得它更容易。 如果没有...
作为一名从事人事劳资工作的人员来说,每次调整工资时填写成百上千的工资审批表存入档案,是一件十分费时费力的工作,并且有时难免会出现一些错误。如果能让电脑来完成这项工作,岂不大大地提高工作效率。因为本人使用Access来管理职工数据库,通过Access与Word的结合,成功地实现了这一功能。下面以1999年事业单位调整工作人员工资标准为...
标签: 电脑入门
不论是桌面客户端还是Web应用通常会出现处理时间较长的操作,为了在这段时间内不影响用户与应用之间的交互体验,开发人员通常会使用异步调用技术,使得比较复杂的逻辑操作由异步进行,用户仍然可以继续使用应用,不会有无响应的等待情况出现。 本篇将通过一个简单的实例演示如何在Windows 8 应用中使用异步编程。首先我们来编写一个Get Blogs...

经验教程

577

收藏

13
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部