Boost logo

Boost Users :

Subject: [Boost-users] [boost::system] Is the library abstraction general enough?
From: Lian Cheng (rhythm.mail_at_[hidden])
Date: 2009-02-20 03:36:53


Hi, all

I'm currently building an asynchronous MySQL client API based on
Boost.Asio, whose error handling is based on Boost.System. And thus, I
wrote some code to wrap MySQL error codes and error messages with
Boost.System.

While writing the code, I found that the library doesn't provide a
general enough abstraction. As the document says, there should always be
only one instance of each error_category class. And each error_code
instance communicates with its error_category through only the error number.

Then here is the problem. MySQL error code is a property of a single
MySQL connection. The mysql_errno() and mysql_error() functions both
require a MYSQL* connection handle as parameter to retrieve the last
error number and error message of the given MySQL connection. And the
error messages provided by MySQL API are actually printf format strings.
The mysql_error() function fills the format strings with information
related to the MYSQL* handle. But in Boost.System, I've got no idea how
to pass the connection handle to the error_category::message() function
so that a proper error message can be retrieved.

Is there any way to fix this problem? Or the library itself is just not
general enough? You see, not all error numbers can be directly mapped to
a well defined error message string.

Cheers
Cheng


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net