Here is the patch that shows the problem I am facing. The issue is that the
test for the success of the query is not a bool type, but rather a void *.
The void * works OK in cases where you want to execute code for both the
success and failure path (if ... else ...), but in my case, I only want to
act in case of failure. I expected that the !query would work, but the
compiler must do something special because the !query doesn't work. I have
to put the following construct:
if (query == 0) {
// Log some error and return
}
I don't especially like this kind of construct. I would rather see the ()
operator be just like the StoreQueryResult and return a bool so that we can
perform the following:
if (!query) {
// Log some error and return
}
Martin
--- /usr/share/doc/mysql++-devel-3.0.9/examples/simple1.cpp 2009-02-05
15:03:49.000000000 -0500
+++ simple1.cpp 2009-06-09 10:20:43.000000000 -0400
@@ -49,8 +49,13 @@
if (conn.connect(db, server, user, pass)) {
// Retrieve a subset of the sample stock table set up by resetdb
// and display it.
- mysqlpp::Query query = conn.query("select item from stock");
- if (mysqlpp::StoreQueryResult res = query.store()) {
+ mysqlpp::Query query = conn.query("selection item from stock");
+ mysqlpp::StoreQueryResult res = query.store();
+ if (!query) {
+ cerr << "Failed to get item list: " << query.error() <<
endl;
+ return 1;
+ }
+ else {
cout << "We have:" << endl;
mysqlpp::StoreQueryResult::const_iterator it;
for (it = res.begin(); it != res.end(); ++it) {
@@ -58,10 +63,6 @@
cout << '\t' << row[0] << endl;
}
}
- else {
- cerr << "Failed to get item list: " << query.error() <<
endl;
- return 1;
- }
return 0;
On Mon, Jun 8, 2009 at 3:47 PM, Warren Young <mysqlpp@stripped> wrote:
> On Jun 8, 2009, at 6:18 AM, Martin Dubuc wrote:
>
> I don't really understand the change you describe to the simple1.cpp
>> example.
>>
>
>
> http://en.wikipedia.org/wiki/Patch_(Unix)#Usage_examples<http://en.wikipedia.org/wiki/Patch_%28Unix%29#Usage_examples>
>>
>
> In your modified example, if
>> the query was bad and exceptions were disabled, then, the code would never
>> get to the "else" section, meaning that it is not possible to detect
>> errors
>> in handling the query.
>>
>
> On following the instructions in the Wikipedia article to apply the patch,
> you will see that it causes simple1 to detect the broken query correctly.
> (Notice that the patch also changed the query string.) A single-character
> change to the patch to un-break the query ("stocxk" -> "stock") will then
> cause simple1 to take the other branch in the if/else.
>
> Therefore, this feature of MySQL++ is not broken.
>
> If you still don't believe me after trying it, modify another one of the
> examples to demonstrate the problem, then post the patch. It's far more
> credible than posting code snippets that don't compile.
>
>
> --
> MySQL++ Mailing List
> For list archives: http://lists.mysql.com/plusplus
> To unsubscribe:
> http://lists.mysql.com/plusplus?unsub=1
>
>