3 messages in com.mysql.lists.mysqlRe: UDF under Windows| From | Sent On | Attachments |
|---|---|---|
| Patricio Díaz G. | 07 May 2003 21:59 | |
| Patricio Díaz G. | 11 May 2003 21:58 | |
| Patricio Díaz G. | 14 May 2003 19:30 |
| Subject: | Re: UDF under Windows![]() |
|---|---|
| From: | Patricio Díaz G. (patr...@cafeinternet.com.py) |
| Date: | 05/14/2003 07:30:24 PM |
| List: | com.mysql.lists.mysql |
It is very simple, just make a .dll with any C++, I especifically use VC++ this time, and define the members of you dll as the documentation says (function_init, function_deinit if used , and function), usin the same scheme and type of parameters the mysql espects to send and receive to/from your function.
Here is the transcription of mi first succed try:
// prueba.h // some definitions
#include <mysql.h>
#ifdef PRUEBA_EXPORTS #define PRUEBA_API __declspec(dllexport) #else #define PRUEBA_API __declspec(dllimport) #endif
#define MY_FUNC_API extern "C" __declspec(dllexport)
// This class is exported from the prueba.dll class PRUEBA_API CPrueba { public: CPrueba(void); // TODO: add your methods here. };
MY_FUNC_API int fnPrueba( UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
// prueba.cpp // #include "stdafx.h" #include "prueba.h" #include <mysql.h>
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; }
CPrueba::CPrueba() { return; }
MY_FUNC_API prueba_init( UDF_INIT *initid, UDF_ARGS *args, char *message) { if (args->arg_count != 1 || args->arg_type[0] != INT_RESULT) { strcpy(message,"Argumentos equivocados\n Uso: Select prueba(int);"); return 1; } return 0; }
MY_FUNC_API prueba_deinit(UDF_INIT *initid) { }
extern "C" my_ulonglong __declspec(dllexport)prueba( UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) { my_ulonglong val; val = *((my_ulonglong*) args->args[0]); return val+2; // add 2 to the value passed and return te result }
you can download the complete project from here: ftp://ftp.cafeinternet.com.py/udf/prueba.rar (my server is down from late night, about 12:00 pm, till 8:00 AM.)
Once compiled, just place a copy under your windows\system folder, tell you server of the new function: CREATE FUNCTION prueba RETURNS INTEGER SONAME "prueba.dll" and that's all, now you hace a function that every time you call it with a integer it adds to that integer 2 and returns you the result.
Please give me some time if you are ineterested in the Zeosudf I have ported to Windows, to contact with the people from Zeos about the license, to port the rest of the functions and document the changes, I just used the code I needed.
----- Original Message ----- From: "wcb" <wc...@shaw.ca> To: "Patricio Díaz G." <patr...@cafeinternet.com.py> Sent: Wednesday, May 14, 2003 2:33 PM Subject: Re: UDF under Windows
Hi!
I'd be very interested in knowing details of how you compiled a working UDF for Win32! Thanks a lot!
Cheers!
-warren
----- Original Message ----- From: "Patricio Díaz G." <patr...@cafeinternet.com.py> To: <mys...@lists.mysql.com> Sent: Sunday, May 11, 2003 9:58 PM Subject: Re: UDF under Windows
I answer to my self, I have found the way to compile a UDF that works with MySQL under Win32, and it is working fine. If anyone is interested in the same thing, just let me know.




