Subject | Re: [firebird-support] Trigger not working |
---|---|
Author | Dmitry Kuzmenko |
Post date | 2014-02-23T15:13:52Z |
Hello, Werner!
Saturday, February 22, 2014, 9:31:19 PM, you wrote:
W> I have the following trigger which doesn't work for me, i.e. the columns
W> in winerackit are never updated by it.
W> In my current test case the 'fk_winerackit_id' column is set to "Null",
W> so I would expect this trigger to fire and set the 'usedcapacity' column
W> to '0' as it was '1' before the update to the bottag table.
W> CREATE OR ALTER trigger bottag_biud0 for bottag
W> active after insert or update or delete position 0
W> if (old.fk_winerackit_id is not Null) then
W> if (new.fk_winerackit_id is not Null) then
maybe that ?
http://www.firebirdsql.org/refdocs/langrefupd21-ddl-trigger.html
In multi-action triggers, both context variables OLD and NEW are always available.
If you use them in the wrong situation (i.e. OLD while inserting or NEW while deleting), the following happens:
- If you try to read their field values, NULL is returned.
- If you try to assign values to them, a runtime exception is thrown.
I think, when using new/old in multi-action triggers you should
directly use context variables INSERTING, UPDATING and DELETING to
avoid ambiguity of the code.
--
Dmitry Kuzmenko, www.ib-aid.com
Saturday, February 22, 2014, 9:31:19 PM, you wrote:
W> I have the following trigger which doesn't work for me, i.e. the columns
W> in winerackit are never updated by it.
W> In my current test case the 'fk_winerackit_id' column is set to "Null",
W> so I would expect this trigger to fire and set the 'usedcapacity' column
W> to '0' as it was '1' before the update to the bottag table.
W> CREATE OR ALTER trigger bottag_biud0 for bottag
W> active after insert or update or delete position 0
W> if (old.fk_winerackit_id is not Null) then
W> if (new.fk_winerackit_id is not Null) then
maybe that ?
http://www.firebirdsql.org/refdocs/langrefupd21-ddl-trigger.html
In multi-action triggers, both context variables OLD and NEW are always available.
If you use them in the wrong situation (i.e. OLD while inserting or NEW while deleting), the following happens:
- If you try to read their field values, NULL is returned.
- If you try to assign values to them, a runtime exception is thrown.
I think, when using new/old in multi-action triggers you should
directly use context variables INSERTING, UPDATING and DELETING to
avoid ambiguity of the code.
--
Dmitry Kuzmenko, www.ib-aid.com