I need to get all the values which changed in a row and post modifications on other 'audit' table. Can I accomplish this, without writing the conditions for each element from the row? I know the SQL from http://www.firebirdfaq.org/faq133/ which gives you all the conditions for verifications:
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';
but this should be written in the trigger. So, if I change a table then I need to modify the trigger.
Due the fact that FireBird does not allow dynamically increasing the size of a varchar variable I was thinking of casting and concatenating all the values to a big varchar variable, before inserting it in a text blob.
Is there any possibility to accomplish this, without using GTTs?
You need some meta programming, but with triggers on system tables that's no problem.
This solution seems to work, even if you have lots of columns.
This tool is the firebirds solution for your problem:
http://www.upscene.com/products.audit.iblm_main.php
Otherwise You can't access the new./old. variables dynamically.
I investigated an execute statement based solution, but it is also a dead-end.