Mimer SQL Documentation TOC PREV NEXT INDEX

Mimer SQL Developer Site

Error Handling

ODBC returns diagnostic information in two ways:

In general, program logic uses the return code to detect a failure and then the diagnostic records to detail the reason for the failure.

Retrieving Warning and Error Messages

If the ODBC driver returns a code indicating anything other than SQL_SUCCESS then the application can call SQLGetDiagRec to retrieve any warning or error messages:

 SQLCHAR     sqlstatus[6];
 SQLSMALLINT msglen, msgno;
 SQLINTEGER  nativeerror;
 . . .
 msgno = 1;
 while (SQLGetDiagRec( SQL_HANDLE_DBC,
                       &msglen) == SQL_SUCCESS)
     msg[msglen] = '\0';
     printf( "SQLSTATE:   %s\n", sqlstatus );
     printf( "Native:     %d\n", nativeerror );
     printf( "Message:    %s\n", msg );
     printf( "\n" );

Diagnostic records are associated with the ODBC handles: environment, connection, statement and descriptor. SQLGetDiagRec requires the handle type and the handle, making the coding of a general-purpose error handler more complex than other programming interfaces.

A warning is indicated by an SQLSTATE class value of '01' (e.g. '01000').

See Return Codes for details.

Mimer Information Technology AB
Phone: +46 18 780 92 00
Mimer SQL Documentation TOC PREV NEXT INDEX