Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » UltraLite - C and C++ Programming » UltraLite C/C++ Common API Reference

ULInitDatabaseManagerNoSQL Next Page

ULRegisterErrorCallback function


Registers a callback function that handles errors.

Syntax

void ULRegisterErrorCallback (
SQLCA * sqlca,
ul_error_callback_fn callback,
ul_void * user_data,
ul_char * buffer,
size_t len
);

Parameters
Remarks

Once you call this function, the user-supplied callback function is called whenever UltraLite signals an error. You should therefore call ULRegisterErrorCallback immediately after initializing the SQLCA.

Error handling with this callback technique is particularly helpful during development, as it ensures that your application is notified of any and all errors that occur. However, the callback function does not control execution flow, so the application should check the SQLCODE field in the SQLCA after all calls to UltraLite functions.

Example

The following code registers a callback function for an UltraLite C++ Component application:

int main(){
    ul_char buffer[100];
    DatabaseManager * dm;
    Connection * conn;
    Sqlca.Initialize();
    ULRegisterErrorCallback(
        Sqlca.GetCA(),
        MyErrorCallBack,
        UL_NULL,
        buffer,
        sizeof (buffer) );
    dm = ULInitDatabaseManager( Sqlca );
    ...

The following is a sample callback function:

 ul_error_action UL_GENNED_FN_MOD MyErrorCallBack(
 SQLCA *  Sqlca,
 ul_void * user_data,
 ul_char * message_param )
{
    ul_error_action rc = 0;
    (void) user_data;
    
 switch( Sqlca->sqlcode ){
     // The following error is used for flow control - don't report it here
     case SQLE_NOTFOUND:
  break;
  
  case SQLE_ULTRALITE_DATABASE_NOT_FOUND:
   _tprintf( _TEXT( "Error %ld: Database file %s not found\n" ), Sqlca->sqlcode, message_param ); 
  break;
          
     default:
            _tprintf( _TEXT( "Error %ld: %s\n" ), Sqlca->sqlcode, message_param ); 
  break;
     }
    return rc;
}
See also