Subject | execute statement |
---|---|
Author | Sergio |
Post date | 2012-08-09T20:03:01Z |
Hello! I'm trying to do a trigger to maintain a history table. I'm using (for the first time!) execute statement. What I want to do is very simple: if a field change I save the old value in the history
When I execute the trigger I get an error:
Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 1, column 1.
if.
I'm sure I'm using "execute statement" in the wrong way !!!
this is the trigger:
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);
for
select
'if (new.' || trim(rdb$field_name) || ' is distinct from old.' || trim(rdb$field_name) ||
') then update tlm_maestro_hist set ' || trim(rdb$field_name) || ' = old.' || trim(rdb$field_name) || ' where id = :loc_nuevo_id;'
from
rdb$relation_fields
where
rdb$relation_name = 'TLM_MAESTRO'
into
:loc_ejecutar
do
begin
execute statement loc_ejecutar;
end
end
When I execute the trigger I get an error:
Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 1, column 1.
if.
I'm sure I'm using "execute statement" in the wrong way !!!
this is the trigger:
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);
for
select
'if (new.' || trim(rdb$field_name) || ' is distinct from old.' || trim(rdb$field_name) ||
') then update tlm_maestro_hist set ' || trim(rdb$field_name) || ' = old.' || trim(rdb$field_name) || ' where id = :loc_nuevo_id;'
from
rdb$relation_fields
where
rdb$relation_name = 'TLM_MAESTRO'
into
:loc_ejecutar
do
begin
execute statement loc_ejecutar;
end
end