MySQL UDF development on Windows

Source: Internet
Author: User
Tags empty include mysql mysql client win32 client
Mysql|window
A bug report has been submitted for a bug in Windows version of MySQL that does not use UDF. But
It seems to me that I made a mistake, and the MySQL technical support staff gave me the perfect solution to share
A moment. Below is the original reply:)

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'll create a UDF that returns a name:

Note:the sample is ugly, but the purpose here
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 + + 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 Ystem32 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)

Make a brief Chinese description of the superfluous.

Sorry, this is not a bug. Now I'm pasting a simple example of a customer that you've been doing for a client, assuming you have
VC + +, source code distribution, and has a normal running of the MySQL server.

I will create a UDF it will be a name:
Note: The example is very rudimentary and is designed to give you an idea of how to handle the UDF at hand.

-Open the MYSQLD.DSW workspace.
-Add new items to this workspace
-Project NAME:MY_UDF//Item Name: MY_UDF
-Select Win32 Dynamic-link Library//Win32 Dynamic Connection libraries
-click OK
-Select an Empty DLL project//an empty DLL item
-click Finish
-click OK
-Add new file My_udf.cpp to 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);
Compatible C
}

Char *my_name (udf_init *initid, Udf_args *args, Char *is_null,
Char *error)
{
char * me = "my Name";

return me;
Calling this UDF will return my name
}
-Press CTRL + N to create a new file.
-Select text Type
-File name:my_udf.def file://filename: my_udf.def
-Edit the file according to the content below.
LIBRARY Udf_example
DESCRIPTION ' Example Using UDF with VC + + '
VERSION 1.0
Exports
My_name

-Right-click the MY_UDF item and select Settings
-Dots/C + + Tab
-Select General
-Add macros Have_dlope to preprocessor definitions
-Select preprocessor
-Add header file path: Additional Include Directories
For example:.. /include
-Press F7 to compile into a DLL.

-Copy My_udf.dll to directory defined by environment variable path
Like \WinNT ystem32.

-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)


ok! welcome you to the MySQL board Exchange UDF design experience! My email is HeartIcy@163.com,
Mobile phone 13706410308. At the same time, our MySQL board is ready to start systematic and continuous translation of MySQL documents,
I hope you will support us to complete this project together.

Hearticy
May 17, 2003 in Jinan, China


Related Article

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.