views:

68

answers:

3

G'Day,

I want to use the Windows API Postmessage() call from inside a MySQL UDF on MySQL 5.1.51 (XP SP3). I know the UDF (Written in Delphi 2006) is working by setting a bogus result for the UDF.

The syntax of the UDF takes two integer params, one for a window handle and the other for a message number. However a call to PostMessage() from inside my UDF causes an exception in mysqld and the service stops.

Any ideas or pointers? Alternatively if anyone can tell me how I am able to simulate IB Events for MySQL via AnyDAC and Delphi OR an alternate approach to getting a notification when a record has changed in the database then please show me the light.

--Donovan

+2  A: 

Your going to run into problems with this approach mainly due to the fact that messaging will only work to the same access level, and within the same session on the same computer. You would be better served by using other methods, such as TCPIP sockets, MailSlots, Memory mapped files, ect.

To best simulate a post message, I would use TCPIP UDP. A good lightweight library that I have used in the past is Synapse. The synapse library from SVN does run quite well against the latest versions of Delphi. The class you will want to use for this is the TUDPBlockSocket.

skamradt
OK. So the next question is whether the UDF will open the socket in the _init and then close it in the _deinit.
TheEdge
I would make this a lazy create. You don't need it until the event needs to be fired, so create it then. In the _deinit check to see if a socket was created and if so then destroy it. Keeps it simple. UDP is a fire and forget protocol. You don't have to wait and listen for a response.
skamradt
+1  A: 

As an alternative to windows messages or TCP/IP, you might want to consider the named pipes answer to this question on sending information between two Delphi programs and this question on what named pipes are.

--jeroen

Jeroen Pluimers
Thanks Jeroen,This is the solution I ended up going with. Wrote a custom UDF that sends information via a Windows Pipe to either the application itself if it is running on the same machine as the DB server or to a simple socket server application to distribute it via TCP.--Donovan
TheEdge
Cool! Glad I could be of help.
Jeroen Pluimers
A: 

While I have had success via the UDF / Windows Pipe route I had another idea leveraging off being able to tap into the information message framework(?) in MySQL. See http://stackoverflow.com/q/3992779/223742

TheEdge