Subject Re: [firebird-support] Check update succeeded
Author Ivan Prenosil
> - How can i check if an update is succeeded? I have to update a
> single row, if the row doesn't exist i have to raise an exception. I
> tried checking SQLCCODE after the updates 'WHEN SQLCODE 100' but that
> didn't workout. Or do i have to do 'IF (EXISTS (SELECT 1 FROM ...
> WHERE ...) prior to doing the update?

Test the ROW_COUNT variable:
IF (ROW_COUNT = 0) THEN ...



> - How can i get hold of the changed exception messagetext in a 'WHEN
> EXCEPTION' block for logging purposes.
>
> BEGIN
> ...
> ...
> if ... then
> EXCEPTION BAD_ENTRY 'Not good'; <-------
> ...
> ...
> if ... then
> EXCEPTION BAD_ENTRY 'Better but still not right'; <-------
> ...
> ...
> END
> WHEN EXCEPTION BAD_ENTRY DO
> BEGIN
> /* 'Not good' or 'Better but still not right' */
> INSERT LOG (...,MessageText,...)
> VALUES (...,???,...) <-------
> END


What about this:

DECLARE VARIABLE msg VARCHAR(80);
BEGIN
msg = 'Not good';
IF (...) THEN EXCEPTION BAD_ENTRY :msg;

msg = ''Better but still not right';
IF (...) THEN EXCEPTION BAD_ENTRY :msg;

WHEN EXCEPTION BAD_ENTRY DO
INSERT LOG (...,MessageText,...) VALUES (..., :msg,...);
END

Ivan
http://www.volny.cz/iprenosil/interbase/