Mimer SQL Documentation TOC PREV NEXT INDEX

Mimer SQL Developer Site


Run-time Errors


Run-time errors and exception conditions (for example warnings) arising during execution of ESQL statements are signaled by the contents of the SQLSTATE status variable described in The SQLSTATE Variable. A list of possible SQLSTATE values is provided in SQLSTATE Return Codes.

The GET DIAGNOSTICS statement can be used to retrieve detailed information about an exception, see the Mimer SQL Reference Manual, GET DIAGNOSTICS, for the syntax description.

The NATIVE_ERROR and MESSAGE_TEXT fields of the diagnostics area retrieved by using GET DIAGNOSTICS are used to get the internal Mimer SQL return code and the descriptive text, respectively, relating to the exception, these are listed in Native Mimer SQL Return Codes.

Testing for Run-time Errors and Exception Conditions

The application program may test the outcome of a statement in one of two ways:

An application program may contain any number of WHENEVER statements, and the statements may be placed anywhere in the program. A separate WHENEVER statement must be issued for each situation (NOT FOUND, SQLERROR or SQLWARNING) which is to be tested.

When an exception condition arises, action will be taken as specified in the WHENEVER statement most recently encountered in the code, for the respective condition.

WHENEVER statements are expanded by the preprocessor into explicit tests. These tests are placed after every subsequent SQL statement in that program until a new WHENEVER statement is issued for the same condition.

Two important consequences follow:

      ...
       GOTO 1025
       EXEC SQL WHENEVER SQLERROR GOTO 1600
 1025  CONTINUE
       EXEC SQL DELETE FROM MYTABLE
      ...
 
Example:
 void print_sqlerror()
 /*
 **  print_sqlerror prints an error message for the latest error.
 */
 {
     exec sql BEGIN DECLARE SECTION;
     int i;
     int exceptions;
     varchar message[255];
     exec sql END DECLARE SECTION;
 
     exec sql GET DIAGNOSTICS :exceptions = NUMBER; /* How many exceptions? */
     for (i=1; i<=exceptions; i++) {
         exec sql GET DIAGNOSTICS EXCEPTION :i
                                            :message = MESSAGE_TEXT;
         printf("%s\n", message);
     }
 }
 

Mimer
Mimer Information Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40
info@mimer.se
Mimer SQL Documentation TOC PREV NEXT INDEX