Error Messages
SourcePro DB handles errors differently depending upon how they are generated. The following sections describe error messages used with the DB Access Module for MySQL.
Errors
Because the DB Interface Module does not simulate behavior that is not provided in the MySQL C API and MySQL SQL grammar, certain functions of the DB Interface Module are reported as errors using the error code RWDBStatus::notSupported.
A broad range of errors can originate from the MySQL C library, the underlying network library, or the MySQL Server. These errors are reported using the error code RWDBStatus::serverError.
No attempt is made to mitigate against such errors, but when an error does occur, information is transferred to DB Interface Module objects as described below.
Errors and RWDBStatus
When an error or warning is generated by an Access Module call to the MySQL API, information about the event is retrieved via calls to either
mysql_error() and
mysql_errno(), or
mysql_stmt_error() and
mysql_stmt_errno(); this information is then transferred to an
RWDBStatus. This
RWDBStatus object is passed as a parameter to the installed error handler. The following list provides the format that
RWDBStatus uses to describe events reported by MySQL:
• errorCode: RWDBStatus::serverError if an error occurred, or RWDBStatus::ok if a warning is being generated
• message: "SQL Execution call failed" if an error occurred, or "Success with info" if a warning is being generated
• vendorMessage1: the native error code parameter output from the mysql_error() or mysql_stmt_error() call, for example "Invalid Table"
• vendorMessage2: [not used]
• vendorError1: the native error code parameter output from the mysql_errno() or mysql_stmt_errno() call
• vendorError2: [not used]
An application can use the mapping shown previously to write an error handler that reports errors on cerr and issues warnings on clog. For example:
void myErrorHandler(const RWDBStatus& stat)
{
if (stat.errorCode() != RWDBStatus::ok) // Errors
cerr << stat.vendorMessage1();
else // Warnings
clog << stat.vendorMessage1();
}
All errors associated with the status will be reported.