How do you test sqlcode=NOTFOUND after a select/updt in a stored proc.
Posted in 1994
I am investigating the use of stored procedures as a method of encapsulating
commonly used code. What I can't figure out is how to determine if a
select, delete or update statement was successful. Yes, I know how to trap
errors, but I want to know if the row was found(SQLCODE!=100).
The following is not acceptable:
LET cnt = SELECT COUNT(*) FROM cust WHERE cust.id = custid;
IF cnt > 0 THEN
UPDATE mytable SET cust.amt = cust.amt + amt WHERE cust.id = custid; END IF
First, there is no guaranty that the row is still there between the select
count(*) and the update. In any real database program one needs to know
whether a SQL statement ACTUALLY succeeded or not. Probably succeeded may
be good enough for demo programs but not for business/accounting applications.
Also, this is not very efficient to have to do two accesses for every
select/update/delete SQL statement.
The second most common code fragment, I have seen, in Informix programs is:
if (sqlca.sqlcode == 100) /* OR != 100 */
It is difficult to believe that something this fundamental could have been
left out of the implementation of stored procedures. I must have missed
something when I read the documentation. Can some one tell me on what page
this very frequently used operation is described.
--
Daniel Wood daniel@starsight.com
The opinions expressed herein are those of myself, my employers, the carriers
of this news message or any other messages for that matter, you the reader and
any of your relations(whether by birth or chromosome count), all life forms
and all inanimate objects.