From: Warren Young
Date: June 10 2009 8:54am
Subject: Re: Detecting errors executing SQL queries
List-Archive: http://lists.mysql.com/plusplus/8608
Message-Id: <4A2F74CE.5040704@etr-usa.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Martin Dubuc wrote:
> I expected that the !query would work, but the
> compiler must do something special because the !query doesn't work.
This behavior is very weird. It must be going through some other
conversion path, perhaps one inherited from std::ostream. I wouldn't be
surprised if it behaved differently on other platforms. I tried it on
CentOS 3 and 5, which fail the way you've reported.
> I have
> to put the following construct:
>
> if (query == 0) {
> // Log some error and return
> }
Another way that works is:
if (!bool(query)) {
Given these two alternatives, I'd personally just rewrite the tests to
work like simple1 does it.
> I would rather see the ()
> operator be just like the StoreQueryResult and return a bool
Query's built that way on purpose. operator bool has problems of its
own, detailed in this article:
http://www.artima.com/cppsource/safebool.html
I don't remember the reason why we couldn't do the safe bool thing in
StoreQueryResult, just that we tried to do it everywhere in v3, but had
to settle for operator bool in some places.
In any case, we can't change the library's ABI again until v4, which is
indeterminately far in the future.