Bug calling a stored procedure from a trigger ???
Posted in 1998
I have a field in a table that each time it changes I must write a record
in a log table.
For that purpose I wrote a stored procedure...
create procedure ins_hist (v_not like t_reclamos.cod_notificacion,
v_est like t_reclamos.estatus_rec)
-- as you can see, sometimes I'm trying to insert a duplicate
on exception in (-268)
trace "se fue por el on exception... dup val";
return;
end exception
-- inserta en el historial de estatus de reclamos
insert into t_his_est_rec
(cod_notificacion, cod_estado, fecha_hora, usuario)
values
(v_not, v_est, current, user); trace "ok";
end procedure;
...that is called from a couple of triggers of the table...
create trigger ins_reclamos insert on t_reclamos referencing
for each row
(execute procedure ins_hist(rec.cod_notificacion,
rec.estatus_rec));
create trigger upd_reclamos update of estatus_rec on t_reclamos
referencing new as rec
for each row
(execute procedure ins_hist(rec.cod_notificacion,
rec.estatus_rec));
Sometimes I'm trying to insert a duplicate value but I don't want
my program to fail for that reason, I just want it to continue,
not even showing an error, so I programmed an exception that
will trap this error in the stored procedure (as you can see in
the code).
If I force the error just calling the stored procedure, it works
just fine: the first call inserts a record and the second doesn't
and it doesn't show an error
set debug file to "/tmp/mads";
execute procedure ins_hist ("C1", "E");
execute procedure ins_hist ("C1", "E");
The problem is that if I force the error by using the triggers
(inserting or updating the table) IT DOESN'T WORK, the second
update fails and shows the -268 error:
set debug file to "/tmp/mads";
update t_reclamos
set estatus_rec = "E"
where cod_notificacion = "C1";
update t_reclamos
set estatus_rec = "E"
where cod_notificacion = "C1";
I've this problem on 2 different machines:
HP-UX B.10.01 9000/887 with INFORMIX-OnLine Version 7.13.UC3
and
HP-UX B.10.20 9000/831 with INFORMIX-OnLine Version 7.20.UC2
The shortcut that I'm using is to "select count" before the insert
and then decide if I insert depending on this, but I'm aware that's
NOT the efficient way to do this.
Any ideas?
--
Manuel A. Daponte Santiago (mdaponte@prtc.net)
MSC No. 54, Montehiedra Town Center,
9410 Los Romeros Ave.
San Juan, P.R. 00926
+1 (787) 7514343 ext. 512