Openbravo开发-开发篇 为字段填加触发器
也在数据库端实现,必须填写正确的前缀。
提供软开关(IF AD_isTriggerEnabled()='N),可以停掉或打开所有的触发器
CREATE OR REPLACE FUNCTION ht_salary_trg()
RETURNS TRIGGER AS
$BODY$ DECLARE
DECLARE
v_IsEmployee CHAR(1);
BEGIN
IF AD_isTriggerEnabled()='N' THEN IF TG_OP = 'DELETE' THEN RETURN OLD; ELSE RETURN NEW; END IF;
END IF;
SELECT IsEmployee
INTO v_IsEmployee
FROM C_BPartner
WHERE C_BPartner_ID = NEW.C_BPartner_ID;
IF v_IsEmployee = 'N' THEN
RAISE EXCEPTION '%', 'Partner is not employee';
END IF;
IF TG_OP = 'DELETE' THEN RETURN OLD; ELSE RETURN NEW; END IF;
END;
$BODY$ LANGUAGE plpgsql;
CREATE TRIGGER ht_salary_trg AFTER INSERT OR UPDATE ON ht_salary
FOR EACH ROW EXECUTE PROCEDURE ht_salary_trg();
需要导出数据库
ant export.database