List:MySQL++« Previous MessageNext Message »
From:Martin Dubuc Date:June 5 2009 8:03pm
Subject:Detecting errors executing SQL queries
View as plain text  
When I switched from version 2.3.2 to version 3.0, I updated the error
handling according to some text I read in the documentation. However, I have
recently found out that this code does not behave as expected. From the
documentation I saw the following code:

                Query
<http://tangentsoft.org/mysql++/doc/html/refman/classmysqlpp_1_1Query.html#a0>
q = conn.query();
                .... use
<http://tangentsoft.org/mysql++/doc/html/refman/classmysqlpp_1_1Query.html#a22>
query object
                if (q) {
                    ... no problems in using query object
                }
                else {
                    ... an error
<http://tangentsoft.org/mysql++/doc/html/refman/classmysqlpp_1_1Query.html#a6>
has occurred
                }


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. I have modeled my code around this code pattern:

                Query
<http://tangentsoft.org/mysql++/doc/html/refman/classmysqlpp_1_1Query.html#a0>
q = conn.query();
                std::ostringstream qstr;
                qstr << "SELECT * FROM foo";
                q << qstr.str() << std::endl;
                mysqlpp::StoreQueryResult res = q.store();
                if (q) {
                    // No problems in using query object
                }
                else {
                    // An error
<http://tangentsoft.org/mysql++/doc/html/refman/classmysqlpp_1_1Query.html#a6>
has occurred
                    ERROR("Query \"%s\" failed: \"%s\"", qstr.str().c_str(),
                          query.error());
                }


Should this work?

I see that looking at boolean value of StoreQuesyResult will tell me if
there was an error or not, but I thought I could do the same on the Query
object.

Martin

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