Example: Handling Deadlocks When Transactions Do Not Contain Cursors
The following example assumes your transactions do not contain a cursor:
exec sql whenever not found continue;
exec sql whenever sqlwarning continue;
exec sql whenever sqlerror goto err; /* branch
on error */
exec sql commit;
start:
exec sql insert into ...
exec sql update ...
exec sql select ...
exec sql commit;
goto end;
err:
exec sql whenever sqlerror call sqlprint;
if (sqlca.sqlcode = deadlock)
or (sqlca.sqlcode = forceabort) then
goto start;
else if (sqlca.sqlcode <> 0) then
exec sql inquire_sql (:err_msg =
errortext);
exec sql rollback;
print 'Error', err_msg;
end if;
end: