I've a trigger that detects a change on a field PHONE_EXT and POSTs an EVENT. I would like to post the Phone_ID with the event in order to use this ID in the client. Is this possible? How?
CREATE TRIGGER tr2 FOR employee
ACTIVE AFTER UPDATE POSITION 0
AS
BEGIN
IF (new.PHONE_EXT <> old.PHONE_EXT) THEN
POST_EVENT 'phone_ext_changed'; <-- I would like to pass a string parameter with record ID
END
This is not possible. The event is a name only, if you add ids or other qualifiers, it simply becomes a different event because it has a different name. When subscribing to events, you can only subscribe by name, you can't use wildcards, and it is not possible to include parameters.
Events are for simple and cheap notification, and Firebird can even coalesce multiple 'posts' of the same event into a single notification to a client, so parameters or values are not supported.
The basic idea is that a client subscribe to events, and then determines what changed and what it needs to react to. You can 'help' the client by - for example - populating a support table that is cheap to query.
Also consider reading the article "The Power of Firebird Events", it is a bit old, but a lot of it still applies as Firebird events haven't changed much.
AFAIK, you cannot pass parameters, but you can get what you want with one of this ideas:
Example 1
Example 2
I'm using both with success in different applications/situations.
You can use it as follows:
Ex.:
"Creating the context variavble"
To capture the saved information use:
Select rdb$get_context('USER_SESSION', 'REGISTRO') from rdb$database;