Hello,
We have Hp-UX 10.20 with Informix 7.3x; we have databases
with transaction logging and some without. In a stored procedure,
I would like to check if an insert fails due to a duplicate (-239/-268),
and then if a duplicate exists, to then do an update. Simple enough
I thought if I use the ON EXCEPTION command. It works great when
I use it on a db without logging (checks for -239), and also works
when I use it via dbaccess on a db with logging( checks for -268).
When I use it through esqlc it does not work, it seems to completely
ignore the fact that the exception handler exists!!!
I have used the trace on and it just seems to verify the failure to
recognize the defined exception. I have tried numerous variations on
the locations of the BEGIN and END statement blocks.
I have included the relevant code below with a few annotations.
Any help would be greatly welcome. Thanks, Mark
(mark.glaudemans@noaa.gov)
=========================================================================
create procedure test_pe
(
postlid char(8),
postprid char(9),
postprodtime datetime year to second,
postposttime datetime year to second
)
define sqlnum int;
define isamnum int;
define counter int;
set debug file to '/tmp/marktest.out';
trace on;
BEGIN
ON EXCEPTION
SET SQLNUM, ISAMNUM
END EXCEPTION WITH RESUME;
select count(*) into counter from productlink
where lid=postlid and product_id = postprid
and producttime = postprodtime and postingtime =postposttime;
[returns count=0]
insert into productlink
values(postlid, postprid, postprodtime, postposttime);[insert works]
select count(*) into counter from productlink
where lid=postlid and product_id = postprid
and producttime = postprodtime and postingtime =postposttime;
[returns count=1]
insert into productlink
values(postlid, postprid, postprodtime, postposttime);
[insert fails as expected due to duplicate (the key to the table is all
of its
four fields shown) but exception not found, and -268
returned to calling esqlc procedure...]
END
end procedure;