Subject | Re: [firebird-support] Logging data changes |
---|---|
Author | Ivan Prenosil |
Post date | 2006-11-27T11:07:05Z |
> We have a requirement from one of our clients to log data changes.Yes, triggers are the best solution - they work independently on used client,
> (For example, changing client or supplier details, logging stock
> movements, that kind of thing)
>
> I was thinking of using triggers to do this. In other words, on the
> stock table for example, writing after insert, after update and after
> delete triggers to track all stock movements including stock sales,
> who made them, date and time, that kind of thing.
>
> Any suggestions? Am I on the right track here?
and they are under transaction control, so you always get consistent result.
Just be careful when detecting whether field value changed -
if you have nullable field, and the value changes from null to not null
or vice versa, than this simple comparation does not work
IF (OLD.MyField <> NEW.MyField) THEN ...
You would have to use something more complex, e.g.
IF (NEW.MyField=OLD.MyField OR
NEW.MyField IS NULL AND OLD.MyField IS NULL)
THEN <...values are euqal...>
ELSE <...value changed...>
>The same test in FB2 would be easier:
> FB 1.5.3 classic.
IF (NEW.MyField IS DISTINCT FROM OLD.MyField) THEN <...value changed...>
Ivan
http://www.volny.cz/iprenosil/interbase/