Subject | Re: [ib-support] OLD context variable behaviour on triggers |
---|---|
Author | Helen Borrie |
Post date | 2002-12-05T12:30:44Z |
At 12:59 PM 05-12-02 +0100, you wrote:
be compared with a value. In fact, it can't even be compared with null.
Your logic needs to be this:
IF ((OLD.ELMEUCAMP!=NEW.ELMEUCAMP)
or (OLD.ELMEUCAMP IS NULL AND NEW.ELMEUCAMP IS NOT NULL)) THEN
NEW.HASCHANGED='X';
heLen
>Firebird 1.0 Win32No - the problem is the null. It is not a value, it is a state. It can't
>Let's suppose this table:
>
>CREATE TABLE PROVA(
>ID INTEGER NOT NULL PRIMARY KEY,
>ELMEUCAMP VARCHAR(8),
>HASCHANGED CHAR(1)
>);
>
>and this trigger:
>
>CREATE TRIGGER MyTriggerBU FOR PROVA
>BEFORE UPDATE AS
>BEGIN
>
>IF(OLD.ELMEUCAMP!=NEW.ELMEUCAMP) THEN
> NEW.HASCHANGED='X';
>
>END
>
>I'm find that, when I change ELMEUCAMP field value from NULL to something
>not null, the trigger doesn't perform the THEN statement !!
>It's to say, if OLD.FIELD=null and NEW.FIELD='ABCD', they are equals for
>the trigger.
>
>Is this normal? Maybe the problem is the VARCHAR type?
be compared with a value. In fact, it can't even be compared with null.
Your logic needs to be this:
IF ((OLD.ELMEUCAMP!=NEW.ELMEUCAMP)
or (OLD.ELMEUCAMP IS NULL AND NEW.ELMEUCAMP IS NOT NULL)) THEN
NEW.HASCHANGED='X';
heLen