List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:August 6 2013 7:36pm
Subject:Re: Problem with a query
View as plain text  
On 8/6/2013 13:02, Joseph Hesse wrote:
> I have included working test code

No, actually, you haven't.  The code you give won't run, because you 
haven't set up a DB schema, and you haven't given the queries.

Rather than go to the effort of doing that, in the future, just modify 
one of the examples to show your point.  Then we can resetdb locally and 
run your code against the example DB.

Another nice thing about this is that you could have submitted just a 
patch instead of a complete program, since connection setup and 
exception handling don't affect your point here, other than to point out 
that you haven't disabled exceptions.  You could have made *that* point 
simply by patching one of the examples that has a full exception 
handler, rather than one of examples/simple*.

>      Query query = conn.query(TempTable1);
>      query.exec();

What happens if you change to execute() instead?

exec() is supposed to be just a minor optimization, but it's probably 
not really pulling its own weight.  From an interface point of view, it 
adds nothing to MySQL++, since SimpleResult can convert itself to bool.

I'm tempted to schedule space for exec() for the chopping block.

>      query = conn.query(TempTable2);
>      cerr << "Size of string TempTable2 is : " << TempTable2.length()
> <<
> endl;

You aren't really reusing the Query object here.  You're creating a 
second one, then replacing the first.

I see that you're trying to keep your code consistent here.  If that is 
really important to you, just create the second Query object explicitly:

     Query query2 = conn.query(TempTable2);

That will actually be more efficient than your existing code, since it 
skips the unnecessary copy of the temporary over the old Query object.

If what you really were trying to accomplish is Query object reuse, I'd 
say this instead after the first execute():

     query << TempTable2;

The Query object is empty after the successful execute(), so this just 
puts the second query into it without replacing the whole object.
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