1

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

TheEdge
  • 9,291
  • 15
  • 67
  • 135
  • 1
    It would help if you posted what exception you're getting... – Mason Wheeler Oct 21 '10 at 02:14
  • Are you running MySQL as a service? I don't think it will have access your desktop windows if you do. I don't think it should crash though. Also Delphi seems like an odd language to write a MySQL UDF in. – Alex Jasmin Oct 21 '10 at 02:23
  • Welcome to Stack Overflow. Your final paragraph asks about how to simulate Interbase events in MySQL. If that's really what you want, then ask that ask a separate question. Don't bury it here in a question about unspecified exceptions. – Rob Kennedy Oct 21 '10 at 02:28
  • Yes I am running MySQL as a service. I don't get any exception. I get Microsoft's "This application has encountered an error and needs to close". The event log shows: EventID: 1000 Category (100) Faulting application mysqld.exe, version 0.0.0.0, faulting module kernel32.dll, version 5.1.2600.5781, fault address 0x00012afb. – TheEdge Oct 21 '10 at 02:55
  • @user223742 Try not running it as a service. – Alex Jasmin Oct 21 '10 at 03:02
  • Hi Rob, Thanks for the advice. Added separate question: http://stackoverflow.com/questions/3983992/implement-mysql-event-notification-back-to-a-delphi-application – TheEdge Oct 21 '10 at 03:07
  • Same behaviour when running it standalone viz: mysqld --standalone – TheEdge Oct 21 '10 at 03:19

3 Answers3

2

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
  • 15,366
  • 2
  • 36
  • 53
  • OK. So the next question is whether the UDF will open the socket in the _init and then close it in the _deinit. – TheEdge Oct 21 '10 at 03:57
  • 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 Oct 21 '10 at 15:51
1

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

Community
  • 1
  • 1
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
  • 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 Oct 22 '10 at 23:18
  • Cool! Glad I could be of help. – Jeroen Wiert Pluimers Oct 23 '10 at 12:33
0

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 https://stackoverflow.com/q/3992779/223742

Community
  • 1
  • 1
TheEdge
  • 9,291
  • 15
  • 67
  • 135