To add error messages for table handlers, the following example may be helpful.
Purpose: Implement the
handler::get_error_message
function as
ha_federated::get_error_message
to return the
handler-specific error message.
Example:
When an error occurs you return an error code. (It should not be in the range of those that
HA_ERR
uses, which currently is 120-159.)When
handler::print_error
is called to convert the handler error code to a MySQL error code, it will enter the default label of theswitch(error)
statement:
handler.cc:1721
default:
{
/* The error was "unknown" to this function.
Ask handler if it has got a message for this error */
bool temporary= FALSE;
String str;
temporary= get_error_message(error, &str);
if (!str.is_empty())
{
const char* engine= table_type();
if (temporary)
my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.ptr(), engine);
else
my_error(ER_GET_ERRMSG, MYF(0), error, str.ptr(), engine);
}
else
my_error(ER_GET_ERRNO,errflag,error);
DBUG_VOID_RETURN;
}
}
Thus the
handler::get_error_message
is called and you can return the handler-specific error message, which is either a static error message that you retrieve from an error/string array, or a dynamic one that you format when the error occurs.
When you have returned the error message it will be passed to
MySQL and formatted as Got error %d '%-.100s'
from %s
. For example:
Got error 788 'Could not connect to remote server fed.bb.pl' from FEDERATED
The Got error %d
part will be returned in the
user's selected language, but the handler-specific one will use
English (unless the handler supports returning the handler error
message in the user's selected language).