Reputation: 333
How can I listen to Firebird events using Delphi DBExpress?
I know Zeos / IBComponents has specialized components for that, unfortunately I can't use those.
Upvotes: 1
Views: 1114
Reputation: 30715
Update I have found a way to add event-monitoring to a DBExpress application that may be applicable to your situation, where it's impractical to re-write the app so as to avoid using DBExpress. Here's what I've done so far, and it works fine.
I wrote a minimal DBExpress application that opens and edits an Interbase table and saves the changes back to the database table. For what I had in mind for this try-out, I decided that it didn't matter that the database is an Interbase one rather than Firebird. Let's call this app DBXApp.
Then I wrote the equivalent app using the Interbase components (IBDatabase, etc) and included event support using an IBEvents component to write the received events to a memo. Lets call this IBApp.
Running DBXApp and IBApp concurrently, IBApp sees the events caused when DBXApp saves changes to the table. So, I thought:
Now, open DBXApp in the IDE in the IDE and copy IBDatabase1, IBEvents1 and Memo1 to it, add the same code as in IBApp to the OnEventAlert
handler (this took literally 90 seconds), recompile and run. Now, the memo in DBXApp sees the table updates posted by IBApp. So, IBApp can see events triggered by DBXApp and vice versa.
Now it seems to me - and this is the bit I haven't done yet - that if your Firebird db is one that the Delphi Interbase components can connect to, you should be able to modify your Firebird app to add event monitoring the same way I did to DBXApp. Of course, it's a big "if" but if your app isn't too recent (and it sounds unlikely that it is), then perhaps an IBDatabase will be able to connect to its FB database.
Steps 1-3 only took me a couple of hours (and quite a lot of that was finding ad fixing a stupid config error I made), so I think it is worth you giving it a try. Let us know how you get on.
Original answer You don't say why you can't use Zeos/IBComponents, but as far as I know, DBExpress does not handle Firebird's Post_Event and, judging by google results, cannot easily be made to, otherwise someone would have done it.
You might take a look at Zeos's source code to see how it implements Post_Event support and then do similar in your project code. Presumably, it would be a matter of registering a callback with Firebird and processing what it sends.
Another place to look is this (quite old) paper about Firebird events. Although Firebird has since diverged from Interbase, I imagine there is still a reasonable prospect of using the IB event-handling mechanism.
Btw recent versions of Delphi comes with the FireDAC db component library which supports event notifications from back-end RDMSs including Firebird. As you'll see here, its event-alerter for Firebird uses the Post_Event mechanism.
Upvotes: 3