Installing a DBTools error handler

Article ID: 900
Last updated: 05 Feb, 2008
Article ID: 900
Last updated: 05 Feb, 2008
Revision: 1
Views: 2964
Posted: 03 Nov, 1997
by Dean J.
Updated: 05 Feb, 2008
by Dean J.
Problem


How do I install a DBTools error handler?


Cause


Installing an error handler at the proper level allows you to see any error or informational messages from the database server.


Action


 Insert this function into your application.  Activate the error handler by placing a call in main() to RWDBManager::setErrorHandler 
before instantiating the database.

void OutputDBStatus (const RWDBStatus& aStatus)
{
if(aStatus.vendorError1() == 5701)
;
else
{
// Print out the error.
cerr << "Error code:" << (int) aStatus.errorCode() << endl
<< "Error message " << aStatus.message() << endl
<< "Is terminal: " << (aStatus.isTerminal() ? "Yes" : "No")<< endl
<< "Vendor error 1: " << aStatus.vendorError1() << endl
<< "Vendor error 2: " << aStatus.vendorError2() << endl
<< "Vendor message 1: " << aStatus.vendorMessage1()<< endl
<< "Vendor message 2: " << aStatus.vendorMessage2()<< endl;
int num = aStatus.errorCode();
if (num!= RWDBStatus::ok)
{
long severity = aStatus.vendorError2();
if ( ( num!= RWDBStatus::vendorLib && num != RWDBStatus::serverMessage ) || severity > 0 )
{
throw aStatus;
}
}
}
}

You could also set the errorHandler method on all of the DML statements
or storedprodcedure explicitly as follows

RWDBStoredProc sproc = db.storedProc("MyStoredproc",conn);
sproc.setErrorHandler(errorHandler);
This article was:   Helpful | Not helpful
Report an issue
Article ID: 900
Last updated: 05 Feb, 2008
Revision: 1
Views: 2964
Posted: 03 Nov, 1997 by Dean J.
Updated: 05 Feb, 2008 by Dean J.

Others in this category