Contents Index Accessing schema information User authentication

UltraLite C++ User's Guide
  Understanding UltraLite Development

Error handling


You should check for errors after a database operation. You do so by using methods of the ULSqlca object. For example, LastCodeOK() checks if the operation was successful, while GetSQLCode() returns the numerical value of the SQLCode.

You may want to include the following error handling code in your application. The handle_error function prints a message for each error that has occurred.

static void handle_error( ul_char const * context ) {
  ul_char buf[80];
  // Report error details...
  _tprintf( _TEXT("Error at '%s' [%ld"), 
    context ? context : UL_TEXT("?"), 
    Sqlca.GetSQLCode() );
  for( ul_u_long i = 1; i < Sqlca.GetParameterCount(); i++ ) {
   Sqlca.GetParameter( i, buf, 80 );
     _tprintf( UL_TEXT(", %s"), buf );
  }
  _tprintf( UL_TEXT("]\n") );
}

// Check for and report errors
#define __HANDLE_ERROR( line )   handle_error( UL_TEXT( "line " ) UL_TEXT( #line ) )
#define _HANDLE_ERROR( line )   __HANDLE_ERROR( line )
#define CHECK_ERROR()   (Sqlca.LastCodeOK() ? (void)0 : _HANDLE_ERROR( __LINE__ ))

For an example of how to use this function, see Tutorial: An Introductory Application.

For more information, see the following class in the API Reference, in the online books:


Contents Index Accessing schema information User authentication