List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:June 10 2009 8:54am
Subject:Re: Detecting errors executing SQL queries
View as plain text  
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:

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.
Detecting errors executing SQL queriesMartin Dubuc5 Jun
  • Re: Detecting errors executing SQL queriesWarren Young6 Jun
    • Re: Detecting errors executing SQL queriesMartin Dubuc8 Jun
      • Re: Detecting errors executing SQL queriesWarren Young8 Jun
        • Re: Detecting errors executing SQL queriesMartin Dubuc9 Jun
          • Re: Detecting errors executing SQL queriesWarren Young10 Jun
            • Re: Detecting errors executing SQL queriesWarren Young18 May