Subject | Re: [firebird-support] execute statement |
---|---|
Author | Alexandre Benson Smith |
Post date | 2012-08-09T20:18:24Z |
Em 9/8/2012 17:03, Sergio escreveu:
see you !
> 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 historyThere is no IF fucntion in FB, did you meant IIF ???
>
> 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
>
>
see you !