火鸟-插入或更新触发器后 [英] firebird - after insert or update trigger

查看:70
本文介绍了火鸟-插入或更新触发器后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一个计算,需要在更新触发器之后为"table1"更新"field1".

I have a calculation in my DB need to update "field1" for "table1" after the update trigger.

更新该字段会导致更新后触发器触发并执行冗长的过程并显示错误.

The problem that updating that field will cause the after update trigger to fire and execute a lengthy procedure and display errors.

请建议在执行更新后"触发器之后如何更新"field1",而又不使更新后"触发器再次执行.

please advise how to update the "field1" after the "After update" trigger has been executed and without making the "after update" trigger to execute again.

我知道我不能将After触发器与NEW配合使用.

I know that I can not use NEW with After trigger.

谢谢

推荐答案

一个可以使用基于上下文变量的自定义锁定机制,以防止重复调用AFTER UPDATE触发器.

One can use a custom locking mechanism based on context variables which prevent from repeating invocation of AFTER UPDATE trigger.

CREATE TRIGGER au FOR table
  AFTER UPDATE
  POSITION 0
AS
BEGIN
  IF RDB$GET_CONTEXT('USER_TRANSACTION', 'MY_LOCK') IS NULL THEN
  BEGIN
    RDB$SET_CONTEXT('USER_TRANSACTION', 'MY_LOCK', 1);

    ...
    Do your update operations here
    ...

    RDB$SET_CONTEXT('USER_TRANSACTION', 'MY_LOCK', NULL);
  END

  WHEN ANY DO
  BEGIN
    RDB$SET_CONTEXT('USER_TRANSACTION', 'MY_LOCK', NULL);
    EXCEPTION;
  END
END

这篇关于火鸟-插入或更新触发器后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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