Subject Re: [firebird-support] Logging data changes
Author Ivan Prenosil
> We have a requirement from one of our clients to log data changes.
> (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?

Yes, triggers are the best solution - they work independently on used client,
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...>


>
> FB 1.5.3 classic.

The same test in FB2 would be easier:

IF (NEW.MyField IS DISTINCT FROM OLD.MyField) THEN <...value changed...>

Ivan
http://www.volny.cz/iprenosil/interbase/