List:MySQL++« Previous MessageNext Message »
From:Martin Dubuc Date:June 8 2009 12:18pm
Subject:Re: Detecting errors executing SQL queries
View as plain text  
Warren,

I am using 3.0.9.

Exceptions are not enabled in my application. I want to verify success of
executing each query with if ... else constructs.

I don't really understand the change you describe to the simple1.cpp
example. If exceptions are enabled, there is no sense in having an if ...
else construct (the else will never be triggered because the application
would throw an exception if there were a bad query) and I have verified that
if exceptions are not enabled (which is my case), a bad query will not
result in evaluating the query object to null. 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.

My question is: Is this a bug in MySQL++?

My understanding is that in the current implementation, operator void * ()
const is useless in the Query object. Unless there is something I didn't
quite understand.

Martin

On Fri, Jun 5, 2009 at 7:08 PM, Warren Young <mysqlpp@stripped> wrote:

> Martin Dubuc wrote:
>
>>                if (q) {
>>                    ... no problems in using query object
>>
>
> [snip]
>
>  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.
>>
>
> Do you have exceptions enabled?  (They are enabled by default.)  If so, the
> bad query is throwing an exception, so it never gets to the 'if'.
>
> I modified examples/simple1.cpp to demonstrate this feature:
>
>  Index: examples/simple1.cpp
>> ===================================================================
>> --- examples/simple1.cpp        (revision 2517)
>> +++ examples/simple1.cpp        (working copy)
>> @@ -50,8 +50,9 @@
>>                        cmdline.user(), cmdline.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("select item from
>> stocxk");
>> +               mysqlpp::StoreQueryResult res = query.store();
>> +               if (query) {
>>                        cout << "We have:" << endl;
>>                        mysqlpp::StoreQueryResult::const_iterator it;
>>                        for (it = res.begin(); it != res.end(); ++it) {
>>
>
> It works fine.
>
> The last changes to this feature were made in 3.0.2, so if you're using
> 3.0.0 or 3.0.1, you should upgrade.
>
> --
> MySQL++ Mailing List
> For list archives: http://lists.mysql.com/plusplus
> To unsubscribe:
> http://lists.mysql.com/plusplus?unsub=1
>
>

Thread
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