List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:November 25 2013 4:08pm
Subject:Re: Problem Catching BadQuery Exception
View as plain text  
On 11/25/2013 06:38, Jake Colman wrote:
> The connection object is created with the default
> constructor so I'm expecting exceptions to be thrown.

Strictly speaking, Connection has no default ctor.

One of the ctors takes a single parameter with a default value that 
enables exceptions, but you could pass false here instead.

> When I execute the
> SELECT using the Query::store() method the exception is not being thrown.

With this trivial patch to MySQL++, the example *does* throw a BadQuery 
exception:

Index: examples/ssqls3.cpp
===================================================================
--- examples/ssqls3.cpp (revision 2735)
+++ examples/ssqls3.cpp (working copy)
@@ -49,7 +49,7 @@

         // Build a query to retrieve the stock item that has Unicode
         // characters encoded in UTF-8 form.
-       mysqlpp::Query query = con.query("select * from stock ");
+       mysqlpp::Query query = con.query("select * from stockx ");
         query << "where item = " << mysqlpp::quote << "Nürnberger
Brats";

         // Retrieve the row, throwing an exception if it fails.

A BadQuery exception continues to be thrown if you rename 'con' to 
'con_' and create a copy of it as 'con' to force use of the copy ctor.

What does Connection::throw_exceptions() return in your program?  Make 
the call immediately before the failing query, to be sure the flag isn't 
changing value between construction and query.

> If you need more info, I'll send a few lines of code that demonstrate the
> problem.

Best to patch one of the examples, since that removes the schema and 
other details as sources of confusion.  If you find that the examples 
work and your code doesn't, study the differences between your code and 
the examples, and try to make one of the two behave like the other.

Thread
Problem Catching BadQuery ExceptionJake Colman25 Nov
  • Re: Problem Catching BadQuery ExceptionWarren Young25 Nov
    • Re: Problem Catching BadQuery ExceptionJake Colman25 Nov
      • Re: Problem Catching BadQuery ExceptionWarren Young25 Nov
        • Re: Problem Catching BadQuery ExceptionJake Colman25 Nov
          • Re: Problem Catching BadQuery ExceptionWarren Young25 Nov
            • Re: Problem Catching BadQuery ExceptionJake Colman25 Nov
              • Re: Problem Catching BadQuery ExceptionWarren Young25 Nov
                • Re: Problem Catching BadQuery ExceptionJake Colman25 Nov
                  • Re: Problem Catching BadQuery ExceptionWarren Young25 Nov
                    • Re: Problem Catching BadQuery ExceptionJake Colman25 Nov
        • Re: Problem Catching BadQuery ExceptionJonathan Wakely25 Nov