Subject | Re: [firebird-support] FB 1.5 triggers - appear to work as 'FOR EACH ROW' |
---|---|
Author | Helen Borrie |
Post date | 2004-07-29T06:00:57Z |
At 05:01 AM 29/07/2004 +0000, you wrote:
A trigger fires atomically on each row affected and a generator steps up
each time GEN_ID is invoked. There is no way that a trigger can know what
happened the last time it fired. There is also no way to "hold" a
generator's current value for the duration of a transaction. Generators -
unlike anything else - perform outside the context of any user transactions.
/heLen
>Hi all,No can do.
>Unless I have missed some doco, it appears that when a trigger is
>defined, it fires once for each affected row. Is that correct? If
>so, does anyone know a way to get FB to for for all rows affected by
>an event (eg update)?
>
>Example code :
>
>create generator volklp30_generator;
>
>create table volklp30_table (
> ai_field bigint,
> string_field varchar(100)
>);
>
>set term ^ ;
>create or alter trigger volklp30_trigger_insert for volklp30_table
> active before insert as
>begin
> new.ai_field = GEN_ID(volklp30_generator,1);
>end^
>
>create or alter trigger volklp30_trigger_update for volklp30_table
> active before update as
>begin
> if (new.ai_field <= old.ai_field) then
> new.ai_field = GEN_ID(volklp30_generator,1);
>end^
>set term ; ^
>commit;
>
>insert into volklp30_table (string_field) values ('insert test');
>insert into volklp30_table (string_field) values ('insert test');
>insert into volklp30_table (string_field) values ('insert test');
>commit;
>
>/* Select here would show 3 records with ai_field in (1,2,3) */
>
>update volklp30_table set string_field = 'update test' where ai_field > 1;
>commit;
>
>/* Select here would show 3 records with ai_field in (1,4,5) */
>/* I would like it like (1,4,4) */
A trigger fires atomically on each row affected and a generator steps up
each time GEN_ID is invoked. There is no way that a trigger can know what
happened the last time it fired. There is also no way to "hold" a
generator's current value for the duration of a transaction. Generators -
unlike anything else - perform outside the context of any user transactions.
/heLen