Mimer SQL Documentation TOC PREV NEXT INDEX

Mimer SQL Developer Site

http://developer.mimer.com


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     msg[SQL_MAX_MESSAGE_LENGTH+1];
 SQLCHAR     sqlstatus[6];
 SQLSMALLINT msglen, msgno;
 SQLINTEGER  nativeerror;
 
 . . .
 
 msgno = 1;
 while (SQLGetDiagRec( SQL_HANDLE_DBC,
                       hdbc,
                       msgno++,
                       sqlstatus,
                       &nativeerror,
                       msg,
                       sizeof(msg),
                       &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').



Upright Database Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40
dbtechnology@upright.se
Mimer SQL Documentation TOC PREV NEXT INDEX