List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:August 6 2013 12:26am
Subject:Re: Problem with a query
View as plain text  
On 8/5/2013 16:51, Joseph Hesse wrote:
> Is the following code OK?  Assume "conn" is valid.  Queries Q1 and Q2
> are MySQL queries written as C++ strings and do not return anything.
>    Query query = conn.query(Q1);
>    query.exec();
>    query.reset();
>    query = conn.query(Q2);  // query.str() is empty after this statement
>    query.exec();

You don't need the reset() call since you aren't using parse().  Query 
objects auto-reset after a successful query otherwise, so that you can 
do this very sort of Query object reuse you're trying here.

> I diagnosed the problem by printing query.str() after both conn.query.

Are you sure you didn't call exec() first, thus auto-resetting the Query 

If not, are you certain the first exec() didn't fail?  If you're 
suppressing exceptions, are you checking return values?  If the query 
fails, the Query object won't auto-reset, on purpose, so that you can 
retrieve an automatically built-up query string for error messages, 
logging, etc:

     if (!query.exec()) {
         cerr << "Query failed: " << query << endl;

If MySQL++ didn't behave this way, those wanting to log failed queries 
would need to cache the query string before executing it, purely on the 
off chance that it would fail.
Problem with a queryJoseph Hesse5 Aug
  • Re: Problem with a queryWarren Young6 Aug
    • Re: Problem with a queryJoseph Hesse6 Aug
      • Re: Problem with a queryWarren Young6 Aug