MySQLUDF development application on Windows _ MySQL

Source: Internet
Author: User
I once thought that MySQL of Windows has a BUG report that UDF cannot be used. However, it seems that I was wrong. the MySQL technical support staff gave me a perfect answer and shared it with everyone. Below is the original reply. Hello, User. Sorry, this is not a bug. Next I will paste a simple example previously made for a customer. Suppose you have VC ++, the source once thought that the Windows version of MySQL had a BUG where UDF could not be used and submitted a bug report. However, it seems that I was wrong. the MySQL technical support staff gave me a perfect answer and shared it with everyone. Below is the original reply.
  
Hello, User. Sorry, this is not a bug. Next I will paste a simple example previously made for a customer. assume that you have VC ++, source code distribution, and a running MySQL server.
  
I will create a UDF with a name:
  
Note: The example is very simple, so that you can understand how to handle the UDF at hand.
  
-Open the mysqld. dsw workspace.
  
-Add a new project to this workspace.
  
-Project name: my_udf // Project name: my_udf
  
-Select Win32 Dynamic-Link Library // Win32 Dynamic connection Library
  
-Click OK.
  
-Select An Empty DLL project // An Empty DLL project
  
-Click Finish.
  
-Click OK.
  
-Add the new file 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 );
  
// Compatible with C
  
}
  
Char * my_name (UDF_INIT * initid, UDF_ARGS * args, char * is_null,
  
Char * error)
  
{
  
Char * me = "my name ";
  
Return me;
  
// Call this UDF to return my name
  
}
  
-Press Ctrl + N to create a new file.
  
-Select the text type.
  
-File name: my_udf.def file: // File name: my_udf.def
  
-Edit the file according to the following content.
  
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
  
-Add the macro HAVE_DLOPE to the pre-processor definition.
  
-Select Preprocessor.
  
-Add the header file path: Additional Include directories
  
Example: ../include
  
-Press F7 to compile it into a DLL.
  
-Copy my_udf.dll to the directory defined by the environment variable path.
  
For example, \ winnt \ system32.
  
-Open the mysql client.
  
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)
  
The following is the original reply from MySQL technical support:
  
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 Uugly, 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.