When I switched from version 2.3.2 to version 3.0, I updated the error
handling according to some text I read in the documentation. However, I have
recently found out that this code does not behave as expected. From the
documentation I saw the following code:
Query
<http://tangentsoft.org/mysql++/doc/html/refman/classmysqlpp_1_1Query.html#a0>
q = conn.query();
.... use
<http://tangentsoft.org/mysql++/doc/html/refman/classmysqlpp_1_1Query.html#a22>
query object
if (q) {
... no problems in using query object
}
else {
... an error
<http://tangentsoft.org/mysql++/doc/html/refman/classmysqlpp_1_1Query.html#a6>
has occurred
}
However, if I construct a Query that contains a syntax error and invoke the
store method, the query object does not return null, as I would have
expected. I have modeled my code around this code pattern:
Query
<http://tangentsoft.org/mysql++/doc/html/refman/classmysqlpp_1_1Query.html#a0>
q = conn.query();
std::ostringstream qstr;
qstr << "SELECT * FROM foo";
q << qstr.str() << std::endl;
mysqlpp::StoreQueryResult res = q.store();
if (q) {
// No problems in using query object
}
else {
// An error
<http://tangentsoft.org/mysql++/doc/html/refman/classmysqlpp_1_1Query.html#a6>
has occurred
ERROR("Query \"%s\" failed: \"%s\"", qstr.str().c_str(),
query.error());
}
Should this work?
I see that looking at boolean value of StoreQuesyResult will tell me if
there was an error or not, but I thought I could do the same on the Query
object.
Martin