> Reading here gives me some chance that it can be possible: > > http://www.firebirdsql.org/refdocs/langrefupd21-ddl-trigger.html#langrefupd21-alter-trigger-changecount > > What I want to do: > > I have two tables: MY_TABLE, MY_TABLE_HISTORY. In MY_TABLE_HISTORY I want to > keep only one row, in this row I want to have an information such as: > > - last timestamp of changes > - last change number(counter) > - last row id which had been changed. > > I would like to update this row basing on the trigger created for MY_TABLE. > > However, there is one trick: if I update / delete/ insert many rows in one > transaction I would like to update data in MY_TABLE_HISTORY only once. > > So for example: If I update 100 records in MY_TABLE in one transaction I am > incrementing only once the last change number, but if I am updating 100 rows > in 100 different transactions I am incrementing the last change number by 100. > > > Is something like that possible? If not, do you have other ideas how to solve > this problem?
Firebird doesn't have statement-levelm but only row-level triggers, which means that a trigger fire only once per statement, independent on how many records have been touched. I haven't tested the following, but you might be able emulate that by setting a flag in the trigger via RDB$SET_CONTEXT to know, hey my trigger fired, then check that flag via RDB$GET_CONTEXT in an ON COMMIT trigger to run some kind of post-process stuff with your desired changes, e.g. processing logged rows from a temporary table etc. Sounds a bit fishy though. ;-) -- With regards, Thomas Steinmaurer http://www.upscene.com/
