List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:June 5 2009 11:08pm
Subject:Re: Detecting errors executing SQL queries
View as plain text  
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.
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