Subject | RE: [firebird-support] FB 1.5 triggers - appear to work as 'FOR EACH ROW' |
---|---|
Author | Alan McDonald |
Post date | 2004-07-29T06:20:24Z |
> Hi all,Instead of using a standard Update statement, use a Store Procedure to
> 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) */
>
> Thanks in advance,
> Jono
update those records. The SP would acquire a new gen value, then assign it
to each field value you desired. You would not need the update trigger in
this case.
Alan