Subject | Re: [firebird-support] Re: execute statement |
---|---|
Author | Alexandre Benson Smith |
Post date | 2012-08-09T20:43:33Z |
Em 9/8/2012 17:19, Mark Rotteveel escreveu:
STATEMENT.
To achieve what he wants he will need to write an app (or stored
procedure, or whatever) that loops trough the fields and generate the
trigger PSQL code like
CREATE OR ALTER trigger tlm_maestro_au0 for tlm_maestro
active after update position 0 AS
declare variable loc_nuevo_id id;
declare variable loc_ejecutar descripcion_larga;
begin
loc_nuevo_id = gen_id(gen_tlm_maestro_hist,1);
insert into tlm_maestro_hist (id,modificado) values (:loc_nuevo_id, current_timestamp);
IF (new.Field1 is distinct from old.Field1) then
update tlm_maestro_hist set Field1 = old.Field1 where ID =
:Loc_Nuevo_ID;
IF (new.Field2 is distinct from old.Field2) then
update tlm_maestro_hist set Field2 = old.Field2 where ID = :Loc_Nuevo_ID;
IF (new.Field3 is distinct from old.Field3) then
update tlm_maestro_hist set Field3 = old.Field3 where ID = :Loc_Nuevo_ID;
end
> I think you need to create an EXECUTE BLOCK statement as text and thenThere is no way to access NEW and OLD context variables inside EXECUTE
> execute that using EXECUTE STATEMENT, however I am not actually sure if
> that would give you access to the NEW and OLD context tables.
>
> Mark
STATEMENT.
To achieve what he wants he will need to write an app (or stored
procedure, or whatever) that loops trough the fields and generate the
trigger PSQL code like
CREATE OR ALTER trigger tlm_maestro_au0 for tlm_maestro
active after update position 0 AS
declare variable loc_nuevo_id id;
declare variable loc_ejecutar descripcion_larga;
begin
loc_nuevo_id = gen_id(gen_tlm_maestro_hist,1);
insert into tlm_maestro_hist (id,modificado) values (:loc_nuevo_id, current_timestamp);
IF (new.Field1 is distinct from old.Field1) then
update tlm_maestro_hist set Field1 = old.Field1 where ID =
:Loc_Nuevo_ID;
IF (new.Field2 is distinct from old.Field2) then
update tlm_maestro_hist set Field2 = old.Field2 where ID = :Loc_Nuevo_ID;
IF (new.Field3 is distinct from old.Field3) then
update tlm_maestro_hist set Field3 = old.Field3 where ID = :Loc_Nuevo_ID;
end