Monday, September 24, 2007

Some time ago, I announced the MySQL UDF Repository. In short, the MySQL UDF Repository tries to be a one stop place to obtain high quality LGPL licensed libraries containing MySQL UDFs, including documentation and binaries. Since the announcement, our Google Group has grown to a 22 members (including a number of MySQL employees and prominent community members), and we've gained a few interesting new UDF libraries:

A library authored by Arnold Daniels with many useful functions to map and export relational data from MySQL to XML.

Another thing that we see happening now is that people are starting to ask for windows binaries. Although we intend to provide binaries for major operating systems, we haven't really got round to it yet for Windows in particular.

I want to make a start now by explaining how to create and run MySQL UDFs on Windows using the Express Edition of the popular Microsoft Visual C++ IDE. I hope this information will be useful to the many MS oriented developers out there that have trouble getting started with MySQL UDFs.

Preparation

Before we can actually start, we need to install and configure some software and obtain a few resources.

Installing Visual C++ 2005 Express Edition

First, you'll need to download and install Microsoft Visual C++ 2005 Express Edition. At present, this is the latest stable release of the free (As in Beer) version of the popular Visual Studio IDE, set up to create, compile and debug C++ programs.

The installation procedure can take a little while, but is otherwise pretty straightforward.

If you already have a paid-for version of Visual Studio 2005, you should not install the express edition (you are at risk of messing up the existing installation if you do). In that case, you should use your paid-for version or alternatively, download the upcoming release (Microsoft Visual C++ 2008 Express Edition, now in Beta) and give that a spin.

Installing the Microsoft Platform SDK

Apart from Visual Studio, you also need to have the Microsoft Platform SDK installed. Although this SDK is officially entitled "Microsoft ® Windows Server® 2003 R2 Platform SDK", it includes the resources for many flavours of Windows, including Windows 2000, Windows 2003 and Windows XP.

Installing the MySQL Development resources

Source files for UDFs contain references to header files supplied by MySQL. The easiest way to obtain them is by installing them using the Setup.exe installer program that you use to install the MySQL Server.

If you are installing a new server, you can ensure that the files are installed by choosing "custom" in the "Setup Type" step of the wizard started by the Setup.exe:

After that, you will be able to choose which features you want to install. You need to ensure that the "C Include files/Lib Files" under the "Developer Components" is selected:

If you are not installing a new server, you should first check to see if you have an include directory immediately beneath the MySQL base direction. If so, you probably don't need to do anything right now.

If you don't have the include directory, it probably means you did not choose to install the "C Include files/Lib Files" when installing the server (by default, they are not installed). Running the Setup.exe program again will offer you the possibility to add new components to the installation:

And from here, you will be led to the step where you can choose to install the include files and library files.

Setting up a VC++EE Project for MySQL UDFs

Once you fulfilled all necessary prerequisites, the next step is to create a Visual Studio Project. In this context, a project is a container for source files, resources, references to existing libraries, as well as a number of options to compile the source files.

Creating a new Project

To actually create the project, we can use the File/New/Project... menu or else the "create project" hyperlink on the the Visual Studio Startpage:

This opens a dialog where we must enter a few details about our project:

For the Visual C++ Express edition, it works best to choose a General/Empty Project. (The paid-for edition of Visual Studio provides templates for projects to create dynamically linked libraries a.k.a. DLLs but as we shall see later on we have to configure this manually.)

We are also required to provide a name for the project. In this case, we use a name that corresponds directly to the source file: lib_mysqludf_udf.

Visual Studio Solution

In Visual Studio, a project is always part of a Solution, which is basically a container for a number of related projects. Because we just started a new project, we are implicitly creating a new solution too, so we have to specify a few things about that as well:

In this case, we create a separate directory for the solution itself, and we use the same name for the solution as for the project. It is important to realize that there can be multiple projects per solution, in which case it probably makes more sense to choose a distinct name for the solution as a whole.

After confirming the dialog, a number of directories and files are created:

Adding a source file

Now it is time to add the source file to our project, so if you didn't download the lib_mysqludf_udf C source file yet, you should do so now. Be sure to copy the lib_mysqludf_udf.c source file to the lib_mysqludf_udf project directory beneath the lib_mysqludf_udf solution directory:

Copying the source file there is just a matter of convenience - I like to keep things that belong together in one place. If you don't keep the file in the project directory, things might may (and probably will) go wrong if you move the source file or the project to another location later on.

Copying the file to the directory still does not formally add the file to the project. To actually add the file to the project, you can right-click the "Source Files" folder beneath the project folder in the Visual Studio Solution Explorer window and use the context menu to add the existing item:

As an alternative to using the menu you can also add the source file to your project by simply dragging it into the Solution Explorer and dropping it into the "Source Files" folder of the project.

If all went well, the source file is now part of the project and can be opened from the solution explorer:

Project Configuration

Although we already defined the structure of the project, we need to configure it in order to compile it. The configuration can be edited through a single dialog which can be accessed by clicking the "Properties" item in the project folder's context menu:

General Properties

We first need to take care of the general configuration. A Visual Studio project can have several configurations - something which is very useful if you want to create different builds (debug or release) from the same project. However, it is a good idea to first configure all project properties that are the same for all configurations. To do that, we choose "All configurations" in the top left listbox of the configuration dialog. (For this example, we do not separately configure for debug and release builds.)

The rest of the configuration process is a matter of editing individual properties. Related properties are organized in property pages, each of which covers a particular aspect of the project. By default, the "General" property page is selected and it makes sense to start editing properties there right away.

In the "General" property page we need to set the "Configuration Type" property to "Dynamic library (.dll)" as we need to be able to load the UDF library dynamically into the MySQL Server.

Configuring the Include path

MySQL UDFs refer to types and contants defined in C header files provided by MySQL. In turn, these refer to header files from the Microsoft Platform SDK. The project does not know automatically where to locate these header files, so we need to configure the project and point it to the location(s) manually.

To specify the location of the header files, we need to activate the "C/C++" property page and edit the "Additional Include Directories" property. You can either directly type the paths in the text box, or otherwise click the elipsis buttons (...) to browse for them.

For this example, we need to specify two locations:

The location of the "include" directory beneath the MySQL installation directory.

The location of the "include" directory beneath the Microsoft Platform SDK installation directory.

Adding the HAVE_DLOPEN macro

The lib_mysqludf_udf.c source file was created using the udf_example.c source file from the MySQL source distribution as an example. The structure of that code uses conditional compilation according to wheter HAVE_DLOPEN is defined:

#ifdef HAVE_DLOPEN

...code goes here...

#endif /* HAVE_DLOPEN */

And this is also used in lib_mysqludf_udf.

I admit that I don't understand why that is there, or what it is supposed to achieve, and I would very much like someone to comment on this blog entry to explain it. Anyway, for Visual C++ it means we have to explicitly define it using a Preprocessor definition:

Configuring the library path

We configured the project to compile a Dynamic-Link Library. For the compiler, this means it cannot just compile the code and package it in a file: the dll target file needs to adhere to a certain specification. In order to make that happen, it needs to link to existing libraries from the platform SDK.

Just like we did for the include path, we need to tell Visual C++ where it can find the libraries it must link to. This can be configured by editing the "Additional Library Directories" property in the "Linker" property page:

In this case, we only need to specify the path of the "Lib" directory find immediately beneath the Platform SDK installation directory.

Compiling the UDFs

At this point, we are ready to compile the project and/or solution. In most cases, you will want to choose the build configuration to choose between a debug or a release build. This can be done by clicking the "Configuration Manager" item in the build menu to invoke the Configuration Manager dialog:

Actually building the project is done using the "Build Solution" or " Build Project" item in the "Build" menu:

The result of building the solution should be as indicated in the screenshot. If the final line does not read

1>lib_mysqludf_udf - 0 error(s), 0 warning(s)

you might want to read the remainder of this section to figure out what the problem is.

Common problems

Of course, no programming task is complete without running into trouble. In this section, a few common problems compiling the project are listed, as well as their solutions.

This is a similar problem. It occurs when you did include the "include" directory beneath the MySQL installation directory but forgot the one beneath the Microsoft Platform SDK installation directory. Because the latter is referenced by the former, both have to be added to the include path.

This indicates that you did not properly configure the path where Visual Studio looks for Additional Libraries. You should revisit the relevant section in this article and ensure the configured path does in fact contain the specified missing library.

Installing the UDFs

If you managed to succesfully compile the project you are ready to install the UDFs in your MySQL Server. Depending on the whether you chose to do a "Release" or a "Debug" build, you will find the lib_mysqludf_udf.dll in the "Release" or "Debug" directory directly beneath the Solution directory respectively:

The .ddl needs to be copied to a location that is accessible to the MySQL Server. For MySQL versions lower than 5.1.19, the bin and/or lib directories right beneath the MySQL installation directory should work. For MySQL version 5.1.19 and beyond, you are required to copy the dll to the plugin_dir. The plugin_dir can be determined by running the following query:

Common Problems

Even if you successfully compiled the solution, you still might run into a few problems at this stage. A few common ones are described in the remainder of this section.

ERROR 1126 (HY000): Can't open shared library 'file.dll'

If you encounter this error, it means that MySQL cannot find the library you are referring to in the SONAME clause of the CREATE FUNCTION statement. You may have made a typo in your statement, or the MySQL may be looking in another location for the libarary than you might think it does. Verify that you typed the correct location. For MySQL 5.1.18 and earlier, ensure that the dll is copied to either the bin and/or lib directory beneath the MySQL installation directory. For MySQL 5.1.19 and beyond, ensure that the file is located in the plugin_dir.

ERROR 1127 (HY000): Can't find symbol 'functionname' in library

If you encounter this error, a few things might be the matter. You might have made a typo in the function identifier in the CREATE FUNCTION statement. Another possibility is that you forgot to add the HAVE_DLOPEN macro to the preprocessor definitions. If needed, revisit that section in this article.

ERROR 1046 (3D000): No database selected

This error occurs when you did not set the default database. The workaround is to set any database as default database using the USE statement:

USE test;

. Arguably this is a bug in the MySQL Server: it somehow thinks we are trying to create a stored function which is bound to a database. It's as if MySQL cannot distinguish between a UDF and a stored function at this point.

This error occurs when the user that is trying to create the function is not privileged to write to the mysql system database. To the best of my knowledge, UDFs are written only the mysql.func table so I would expect that granting privileges on that table would be enough to be allowed to create UDFs. It turns out that this is not the case. Granting all privileges on the mysql database does allow a user to install UDFs, but I don't know if that is indeed the minimal set of privileges required to install UDFs.

Using UDFs

If you succesfully installed the UDFs, any user will be able to use them, regardless of the setting for the default database . Here is a quick set of examples for lib_mysqludf_udf. The examples in itself are not very useful in itself, but you they can be useful tools for general UDF development when debugging or testing. Also, you can learn from the code how to work with the UDF interface)

Yeah, it felt like kind of a drag at the time to provoke them and catch the output for this write up, but I ran into all of these problems myself at some point, so I figured it might be useful for others to get a quick pointer to the solution of the problem.

Anyway, at some point you explained to me what this HAVE_DLOPEN thing is, but I forgot. Do you remember? If, just leave a comment for posterity ;-)

Finally, finally got around to reading this tutorial. An excellent explanation of a fairly convoluted process. Everything worked swimmingly and was extremely easy to follow - even for a C++ dummy like me. I originally installed XAMPP from Apache Friends, so that whole part about the MySQL Server Installer was a bit unfamiliar to me. However, the XAMPP installation seems to provide the include directory by default so I was able to skip that step altogether.

Well done, and thanks - it's the first explanation of this subject that I've come anywhere close to being able to understand. OK, so now to start writing my own...

When I received the error "ERROR 1126 (HY000): Can't open shared library 'file.dll'" it was a problem with the binary itself rather than it's location. Recompiling the DLL fixed the issue. I don't know for sure but I'm assuming that it had to do with it being compiled against an older version of the MySQL libraries.

Hi:Thanks, this is an excellent article.I have only one complain:There are some "header" files that I can't find, even searching within all my computer.I have copied some of them from my LINUX" machine, but apparently, they aren't compatible with the former.Where can I find the missing ".h" files?- libxml/tree.h- etc.

@marcoR-it: whoops, I just noticed this comment - apperently I never answered you, I apologize.

"Where can I find the missing ".h" files?"

Gosh, I don't know...it depends on what you are trying to do...libxml/tree.h sounds like something you should get off the libxml project.

@Craig: thanks for your kind words! I'm so glad you liked it! Regarding your problem: you just ran into a gotcha...the init function must return 0 (false) inn case all is well, and 1 (true) in case some error occurred.

So this is why you get the error message: MySQL can't init the UDF because you are telling the server something's wrong.

Now, in C, a "string" is simply a stretch of bytes - a byte array. Now C has quite a tight coupling between data structures and how they are represented in memory. Just like a char is a byte in memory, a "string" is actually a range of bytes. All C needs to work with it is it needs to know where the string starts (location of the first byte) and it has to know where it ends. Start location is denoted using a pointer - a pointer is basically an integer that represents an address in memory. If we continue the previous example:

So ptr is now a string that reads "c"...or well, almost. Although we know the start of the string (it is at the address stored in ptr) we stil don;t know the end of the string. This is solved by terminating strings with a special character, 0 (the NUL byte, numeric value zero)

If you write a string literal, it is automatically terminated by the zero char. Consider this:

Hi Roland,I've tried to install the lib_mysqludf_sys library from http://www.mysqludf.org/lib_mysqludf_sys/index.php, I've followed your tutorial, I compiled the library but I received the error "ERROR 1126 (HY000): Can't open shared library 'lib_mysqludf_sys.dll'". My plugin_dir points to the proper (apparently) dir:

mysql> show variables like 'plugin_dir';+---------------+-----------------------------------------------------+| Variable_name | Value |+---------------+-----------------------------------------------------+| plugin_dir | C:\Program Files\MySQL\MySQL Server 5.1\lib\plugin/ |+---------------+-----------------------------------------------------+1 row in set (0.00 sec)My mysql version is: Ver 14.14 Distrib 5.1.34, for Win64 (unknown)I tried to insert manually in mysql.func INSERT INTO mysql.func (name,dl) VALUES ('lib_mysqludf_sys_info','C:\Program Files\MySQL\MySQL Server 5.1\lib\plugin/lib_mysqludf_sys.dll');and afterwards try to create the function CREATE FUNCTION lib_mysqludf_sys_info RETURNS string SONAME 'lib_mysqludf_sys.dll'; but I got all the time the same error :(Do you know what Could I do?Thank you in Advance,Gorka(sorry for my English)

Hi again,actually, I though that the first line #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)will detect my 64bits system but now you tell me that I'm not sure. Anyway, I gonna install the 32bit MySQL and compile for 32 and tomorrow or so I'll tell you the result. You're very quick replying!Thanks,Gorka

Hi Roland,yes, I'm running MS VC express and I don't know what the problem was but I finally tried with MySQL 32bits and it runs perfectly!! Thank you for your advice. Your tutorial is very helpful!Thanks again,Gorka

Hi Rolando, your tutorial is very good, i made with sucess a udf to return the serial of Volum C.but to install the dll in a custumer server i need to install C++ redistributable package..how i can create a no dependency Dll ?

glad you liked it. I am not entirely sure how to do it, but I think there must be some compiler flag that can wrap all dependencies in your target lib. If I find it, I'll try and remember to post it. But in the mean while, please look at all compiler options to see if you find something.

Hi, Roland, your tutorial is very useful. Thank you very much.I compile my c program on solaris, and I have no right to write the MySQL installation directory, Would you please tell me how I can install the *.so file to let mysql know where the file is? Thanks

Hi, Roland, your tutorial is very useful. Thank you very much.I compile my c program on solaris, and I have no right to write the MySQL installation directory, Would you please tell me how I can install the *.so file to let mysql know where the file is? Thanks

Roland, thank you very much.now I install mysql5.0 on another PC, the OS is fedora8, I use yum to install mysql, but I don't know to put *.so to which directory, the reference manual of MySQL says copy *.so to /usr/lib/, but it can't work. When I execute (CREATE FUNCTION...), error 1126,no such file.How should I do to solve this problem? thanks again.

Hi Roland,I've gone through the tutorial and completed the tasks. Right now, I'm trying to create a MySQL UDF in visual C++ that connects to a remote SQL Server 2005 database using SQLAPI. I'm not making much progress because it seems that the complier doesn't like the class syntax. Is such a connection possible?

I've also questioned whether or not the UDF is the right tool for the job. The alternative is to put this functionality in the application layer which I might do. But regardless I would like to see the options that are available.

I recently needed to do this but using Windows Vista x64 and Visual Studio 2008. The overall process was similar but there are a few differences to note:1) Visual Studio 2008 comes with the platform SDK included. Thus, I did not need to add the platform SDK paths noted above. (You will find the platform SDK includes/libs in C:\Program Files\Microsoft SDKs\Windows\v6.0A)2) I am running 64-bit mysql server and so I had to compile a 64-bit binary. Failing to do so would result in the "ERROR 1126 (HY000): Can't open shared library 'file.dll'" when attempting to create the function in MySQL.3) After compiling everything and resolving the file open problem, I still got the "ERROR 1127 Can't find symbol". I was sure I spelled everything correctly and had defined HAVE_DLOPEN when compiling. Turns out, my UDF code was not windows friendly. You must have __declspec(dllexport) before each extern'd item for it to be actually exported in the dll. You can verify your functions are exported by using the VisualStudio command prompt and typing: dumpbin /exports file.dllThe recommended way of marking up your UDF for Windows support is this:#if defined(_WIN32) || defined(_WIN64)#define DLLEXP __declspec(dllexport)#else#define DLLEXP#endif

I'm impressed! In 10 Minutes I had the sample working in MySQL 5.1.48 (compiled with Visual C++ 2008 Express Edition).The configuration was easy (no path to Plattform SDK needed).Now I'll start the serious work :-) the Damerau-Levesthein distance for string comparison. When finished I'll send you the code.Eugen Schülter

glad to hear this got you started so quickly - thanks for letting me know.

If you want to contribute some code, that's great! Please visit mysqludf.org and find contact details there. I will be on vacation and not answering mail as regularly as usual, this way it will get picked up sooner.

Hi Roland. I am attempting to install the lib_mysqludf_stat ( version 0.0.3) udf on Vista from the UDF repo. I used VC Studio express 2010 to compile it with the MySQL 5.1.33 server complete with the include and lib directories.

Thanks for the info Roland. I finally got the UDF compiled and get to see system calls working. However i now have another query related to triggers if u can answer. I'm trying something like this in TRIGGER CODE:

CREATE TRIGGER upd_check AFTER INSERT ON FOR EACH ROWBEGINsys_exec('TimeOutBatch.sh')END;

from the error log i understood that way of calling sys_exec is wrong. can u suggest the correct way. My aim is to call the shell script in the trigger.

Glad you got that working. Your last question does not seem to have any direct bearing on the main blog article. I'll answer this time around, but please use public forums and google next time you want to ask questions that are not related to this blog.

Thanks in advance.

UDFs are functions. You should use the proper syntax to invoke the functions - either use:

you wrote about high quality?? I just tested the lib_mysqludf_sys for Windows, in particular the sys_eval() function which sucks totally. It is simply not working that way and if you really compile this code for windows and execute it via a mysql-udf-call, the mysql-server will crash.

Who told you that _popen() will work under Windows as it does under Linux/Unix? Pure bullshit, if one really needs these async-calls made, please refer to the msdn before porting ..nix-code to Windows.

I guess when one is crafting open source software his/her spirit is: Hey, it compiles - ship it!

thank you so much for your constructive criticisms. And thanks for the patches too - we'll be able to fix all the problems you just mentioned in a snap because of your kind contributions. You're really, really too kind, and we're humbled by your modest and sincere gesture.

Hi Roland,I have ported my UDF to TCP usage. Now I get a "connection refused" error. Even though my client is running and listening to the correct port. Might be worth mentioning, that I am doing this in windows environment. So far I have only found examples for Linux.

Could it be that this is a windows specific problem? Except for the libraries used, my source code is practically identical to linux-based opeb source examples online.

Hi, Roland.I have knowledge about .net clr udf, but only for MSSQL, so I find your article great.I have couple of questions. First of all I have only basic experience in C and I do not know how to solve it.

You are a great expert in compiling UDF's with MS Visual C++. Due to the good instruction in this blog, I was successfully able to implement your udf's in mysql. Many Thanks!

In the meantime, I've tried to add a udf ("median.cc") to mysql - following your instruction - from an external page (see below) but it didn’t work. I got a ErrorMsg in MySQL (Can`t find symbol 'median' in library) while executing in MySQL: CREATE AGGREGATE FUNCTION median RETURNS REAL SONAME "Median_udf.dll" Could you help me, please?

Kind Regards, Testuser

UDF Soure Page:http://mysql-udf.sourceforge.net/

Download link on this page: http://sourceforge.net/projects/mysql-udf/files/mysql-udf/mysql-udf-0.3/mysql-udf-0.3.tar.gz/download

Hi, I write a UDF to run system(command). However, the commands like "Java","Java helloworld" never work. An error number 1 is returned. If system(command) is called in a C++ program, it wroks for all kinds of commands.

My SQL server is 5.5.

I also used the udf system() to run a program inside mysql. The program is to send a http requester. The program runs successfully outside mysql. However, if using udf call, the final step of sending http request (HttpSendRequest) will never work.

I am running mysql5.5 on windows 7. I am using microsoft WinINet to send http requester. The program alone has been tested to send the http request successfully. Then I transferred the code and make the DLL file mysql needs. The UDF just fails to send the http request.

"I also used the udf system() to run a program inside mysql. The program is to send a http requester. The program runs successfully outside mysql. However, if using udf call, the final step of sending http request (HttpSendRequest) will never work."

Did you try to execute something very basic with your udf, like 'dir' or 'del'? Did that work?

I try to install it on Ubuntu 12.04 LTS no apparmor installed and i installed the libmyslqclient15-dev

but still get this error

Compiling the MySQL UDFgcc -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o /usr/lib/lib_mysqludf_sys.so/usr/bin/ld: /tmp/cckbh4Er.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC/tmp/cckbh4Er.o: could not read symbols: Bad valuecollect2: ld returned 1 exit statusmake: *** [install] Error 1ERROR: You need libmysqlclient development software installedto be able to compile this UDF, on Debian/Ubuntu just run:apt-get install libmysqlclient15-dev

when you install i get this message:ERROR 1126 (HY000) at line 29: Can't open shared library 'lib_mysqludf_sys.so' (errno: 0 /usr/lib/mysql/plugin/lib_mysqludf_sys.so: cannot open shared object file: No such file or directory)ERROR: unable to install the UDF

and this is because the compiler put the file /usr/lib/lib_mysqludf_sys.so

but the rest of the script search the file in here /usr/lib/mysql/plugin/lib_mysqludf_sys.so

OK Roland, so you say the link to the main file lib_mysqludf_udf.c is broken and we should just type out the code ourselves, but what *is* the code? What is the text inside this file that no longer exists?

I have just discovered your blog while searching for a solution of my problem, which I have posted on stackoverflow. I wanted to ask you whether it is possible to have a look at this issue as you seem to be an expert in creating MySQL UDF's. I would really appreciate it. Here is the link to the post. Cannot install MySQL UDF

hey, this is not a very easy question to answer. You can use the sys_exec udf to run the php command line, but it's really not a good solution for many reasons. You could technically write your own udf that invokes php, but I would not recommend that kind of project to a beginner. Perhaps you can explain what your script does? Perhaps you can solve it in a diffeent way?

Thanks a lot for this. I downloaded a copy of the .so from GitHub, however, had problems creating the functions. I knew I had to recompile it but I had no idea where to start! This was exactly what I needed, so thanks a lot for the information :))

Great Article!I am using mingw32 instead of visual studio. I am trying to build some calls for http_get and http_post to control some internal devices (private subnet). I have successfully built and ran your sample. I know I can just punk out and do sys_exec('curl.exe'), but what I am trying to do is call out to libcurl.dll. Does the plugin DLLs reach out to other DLLs in the OS path? Whenever I have calls in my code that call out to import functionality from libcurl, I cannot CREATE (get 1126 error), however if I comment them out and just put fake text to test the plumbing, all works. I cannot for the life of me get it to see the dll.

I built the mingw version of curl (C:\curl-7.41.0\) (mingw32-make.exe mingw32) and copied libcurl.dll into plugins.

Well, I finally punked out and built sys_eval. First thing I tried was CD (was mysql data dir), next was PATH (was missing the path I added to my env even though I restarted mysql).From this, I figured out the error of my ways. Needed a reboot since mysql was running as system user and not the me.

hi Roland, I am using windows, I have created an trigger that will give call to php script eventually when it gets fired. I have tried using sys_exec() and sys_eval() but none works in my case. can you please suggest me the flow I should maintain to get it done.

Dear Roland, Thanks for quick reply , I am creating the new project in vs 12 version but while downloading the c source file I found that the above link is no longer available.Can you explain what is C and its header files contains or can you please forward those files to me ? my mail id is: sandysachin@gmail.comthank you.

hi Roland, I have pulled the source code from GIT related lib_mysqludf_sys and currently working on it as per your steps, will let you know when it will get done.Really awesome stuff by you thanking you

I have followed your tutorial and created a lib_mysqludf_sys.dll file and placed it in the lib/plugin folder. I've got as far as using the CREATE FUNCTION syntax in the MySQL client and after sorting ERROR 1126 (no file or directory) - I'm now getting a ERROR 1124 - No paths allowed for shared library. I've been googling this for nearly 2 days and can't find a solution or detailed description of the error. Any help would be greatly appreciated.

Do you see a path that you expect for the plugin dir?In the CREATE FUNCTION statement, you should only need to put the filename of the dll - not the path (because the path is implied - it can only be the plugin dir).

Thanks for the great post. I am a newbie in MySql and currently I am looking for similar functionality on Email through C++ dll. Can you please help me to know if its possible to send email through Mysql UDF?

I have done MSSQL CLR to send email with attachment. But I have no idea how to do in MySql.

thanks for interest! I don't think there's anything MySQL specific about what you want to do - once you implement the MySQL UDF interface and you have your UDF installed, MySQL doesn't care what you do once it gets called - calculate a value, run some javascript, or send email - it's all the same.

So basically what you need to do is figure out how to send email in C or C++, once you got that working, you have to design an interface for your UDF: what will the SQL user have to pass to your function so that you can send email. And then you put them together.