是否可以在firebird事件中使用参数:POST_EVENT'event_name'+字符串args? [英] Is it possible to use arguments with firebird events : POST_EVENT 'event_name' + string args?

查看:50
本文介绍了是否可以在firebird事件中使用参数:POST_EVENT'event_name'+字符串args?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个触发器,可以检测字段 PHONE_EXT 上的更改并发布事件.我想在事件中发布 Phone_ID ,以便在客户端中使用此ID.这可能吗?怎么样?

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

推荐答案

AFAIK,您不能传递参数,但是可以通过以下一种方法获得所需的结果:

AFAIK, you cannot pass parameters, but you can get what you want with one of this ideas:

  • 如果您对客户感兴趣的是特定记录上的事件,则可以附加更改记录的ID并发布该事件.客户使用感兴趣的特定ID注册感兴趣的事件.参见示例1.
  • 如果您的前端对所有更改都感兴趣,但您想知道哪些特定记录已更改,则可以将这些记录标记"为最近更改"(使用同一记录的另一个字段或明细表来例子).收到客户通知和操作后,它将还原或清除该标志.例如,可以使用辅助表来跟踪特定客户端的缺失记录,从而获得这种方法的支持,具体取决于您的需求.
  • If in your client you're interested in events over specific records, you can append the ID of the changing record and post that event. The clients register the events in which are interested using the specific ID's of interest. See example 1.
  • if your front-end are interested in all changes but you want to know which particular records changed, you can "flag" the records as "recently changed" (using another field on the same record, or a detail table, for example). Upon client notification and action it reverts or clears the flag. This approach may be powered, for example, using auxiliary tables to track missing records from specific clients, it depends on your needs.

示例1

begin
  if (new.phone_ext <> old.phone_ext) then
    post_event 'phone_ext_changed_'||new.ID;
end

示例2

begin
  if (new.phone_ext <> old.phone_ext) then
  begin
    new.recent_ext_change = 1;
    /* or maybe */
    new.last_ext_change = cast('now' as DateTime);
    /* or maybe */
    insert into changed_phone_ext values (gen_id(some_generator, 1), New.ID, 'now');
    /* finally, post the event */
    post_event 'phone_ext_changed_';
  end
end

我在不同的应用程序/情况下都成功地使用了两者.

I'm using both with success in different applications/situations.

这篇关于是否可以在firebird事件中使用参数:POST_EVENT'event_name'+字符串args?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆