A bug report was submitted to the UDF bug in the WINDOWS version of MySQL. But it seems that I am wrong, MySQL's technical support staff gave a very perfect answer, share it with you. Next 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 serverrunning, I will create a udf That Returns a name:
Note: The Sample Is Ugly, But The Purpose Here Is To Show You Howto 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
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_EXAMPLEDESCRIPTION 'Example Using UDF with VC ' VERSION 1.0EXPORTS 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 DIRECTORES EG: ../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 -penter password: welcome to the mysql monitor. Commands end with; or /g.your mysql connection ID is 2 to Server version: 3.23.52-max-nttype '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)
Drawn from the Snake Added.
Sorry, this is not a bug. Below I pasted a special example for a customer, assuming that you have VC , source code distribution, and have a normal running mysql server.
I will create a UDF which will be a name: Note: The example is very simple, the purpose is to let you know how to handle the UDF of the hand.
- Open the MySQLD.DSW workspace. - Add 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 Item - Click Finish - Click OK to add new file my_udf.cpp to the project: #include
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; // Call this UDF will return my name} - Press Ctrl N to create a new file. - Select TEXT Type - File Name: my_udf.def File: // File Name: My_UDF.DEF - Edit the file below. Library UDF_EXAMPLEDESCRIPTION 'EXAMPLE USING UDF with VC ' Version 1.0Exports my_name
- Right-click the MY_UDF project and select Settings-Point C / C tab - Select General - Add Macro Have_dlope to Preprocessor - Add First File Path: Additional Include Directories, for example: ../include-Press F7 to compile A DLL.
- Copy my_udf.dll to the directory defined by the environment variable PATH, such as / Winnt / System32.
- Open the MySQL client
C: / mysql-udf / bin> mysql -uroot -penter password: welcome to the mysql monitor. Commands end with; or /g.your mysql connection ID is 2 to Server version: 3.23.52-max-nttype '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 everyone to 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 systematically sustainable translation of the mysql document, I hope everyone will support the completion of this project.
Heartcy May 17, 2003 Jinan, China