Subject | Re: [firebird-support] trigger -> know changed fields? |
---|---|
Author | Yves Glodt |
Post date | 2006-02-01T16:33:31Z |
Milan Babuskov wrote:
> Yves Glodt wrote:sure you did! nice idea! :-)
>> I wonder if I fire a trigger on update, is there a possibility of
>> knowing which fields have changed, or do I have to do that "manually" by
>> comparing .old and .new ?
>
> Manually. You also have to take care of NULLs:
>
> if (new.x is null and old.x is not null or
> new.x is not null and old.x is null or
> new.x <> old.x) then
> -- x has changed
>
> You shouldn't do it manually - generate it. It should be simple: for each
> table column, replace "x" in the above example with field name...
>
>
> select 'if (new.' || rdb$field_name || ' is null and old.' ||
> rdb$field_name || ' is not null or new.' || rdb$field_name ||
> 'is not null and old.' || rdb$field_name || ' is null or new.' ||
> rdb$field_name || ' <> old.' || rdb$field_name || ') then'
> from rdb$relation_fields
> where rdb$relation_name = 'EMPLOYEE';
>
>
> Ok, that could be a start. You can also trim field names (and cast to varchar)
> so you don't get the spaces, and add newlines, BEGIN..END block, etc.
>
> HTH