在Windows上的MySQL UDF开发应用_MySQL
曾以为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)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

Deleted something important from your home screen and trying to get it back? You can put app icons back on the screen in a variety of ways. We have discussed all the methods you can follow and put the app icon back on the home screen. How to Undo Remove from Home Screen in iPhone As we mentioned before, there are several ways to restore this change on iPhone. Method 1 – Replace App Icon in App Library You can place an app icon on your home screen directly from the App Library. Step 1 – Swipe sideways to find all apps in the app library. Step 2 – Find the app icon you deleted earlier. Step 3 – Simply drag the app icon from the main library to the correct location on the home screen. This is the application diagram

The role and practical application of arrow symbols in PHP In PHP, the arrow symbol (->) is usually used to access the properties and methods of objects. Objects are one of the basic concepts of object-oriented programming (OOP) in PHP. In actual development, arrow symbols play an important role in operating objects. This article will introduce the role and practical application of arrow symbols, and provide specific code examples to help readers better understand. 1. The role of the arrow symbol to access the properties of an object. The arrow symbol can be used to access the properties of an object. When we instantiate a pair

Editor of Machine Power Report: Wu Xin The domestic version of the humanoid robot + large model team completed the operation task of complex flexible materials such as folding clothes for the first time. With the unveiling of Figure01, which integrates OpenAI's multi-modal large model, the related progress of domestic peers has been attracting attention. Just yesterday, UBTECH, China's "number one humanoid robot stock", released the first demo of the humanoid robot WalkerS that is deeply integrated with Baidu Wenxin's large model, showing some interesting new features. Now, WalkerS, blessed by Baidu Wenxin’s large model capabilities, looks like this. Like Figure01, WalkerS does not move around, but stands behind a desk to complete a series of tasks. It can follow human commands and fold clothes

The Linuxtee command is a very useful command line tool that can write output to a file or send output to another command without affecting existing output. In this article, we will explore in depth the various application scenarios of the Linuxtee command, from entry to proficiency. 1. Basic usage First, let’s take a look at the basic usage of the tee command. The syntax of tee command is as follows: tee[OPTION]...[FILE]...This command will read data from standard input and save the data to

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

"Understanding VSCode: What is this tool used for?" 》As a programmer, whether you are a beginner or an experienced developer, you cannot do without the use of code editing tools. Among many editing tools, Visual Studio Code (VSCode for short) is very popular among developers as an open source, lightweight, and powerful code editor. So, what exactly is VSCode used for? This article will delve into the functions and uses of VSCode and provide specific code examples to help readers
