From: Warren Young
Date: November 7 2007 9:39pm
Subject: Re: Issues with multi-queries
List-Archive: http://lists.mysql.com/plusplus/7146
Message-Id: <47323089.3040904@etr-usa.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Paul Martin wrote:
>
> Sleep function...
It's a bad sign when your program needs to call Sleep() to function
correctly. Race conditions galore lie down that path.
> note that you must add a 'dbtest' database and a user called 'TestApp'
> using 'password' with rights to that db.
Why make us create a special database and user for you, when you can
modify your example to do its work in the MySQL++ example database? If
the problem goes away or changes when making that conversion, you've
learned something that may point you to a fix.
> cout << "Connection fried... ";
> Sleep(10);
Tiny little delays like this are particularly suspect.
> try {
> // Execute query and print all result sets
> Result res = query.store();
> res.purge();
You don't need to call purge() yourself. It's a cleanup function within
ResUse and Result. It's not going to be public any more in v3.
I'm also concerned about whether you've elided code in this area: is
there actual work done between the store() and purge() calls? Also, if
you're using res after the purge call, Bad Things (TM) will happen.
> query << "BEGIN WORK;" << endl;
All these newlines are garbage to MySQL's query parser. Maybe it
happens to ignore them in all cases that matter to you, or maybe they're
part of the problem.
Also, you should be using MySQL++'s Transaction class here for exception
safety instead of rolling your own SQL. See section 3.9 in the user manual.
> query << "SET FOREIGN_KEY_CHECKS=0;" << endl;
> query << "DROP DATABASE IF EXISTS dbtest;" << endl;
You do know you don't have to do these insertions in separate C++
statements, right? This works fine:
query << "BEGIN WORK;" <<
"SET FOREIGN_KEY_CHECKS=0;" <<
"DROP DATABASE IF EXISTS dbtest;" <<
...
;
> query << "INSERT INTO Status
> VALUES(1,29,2,1,'20071106111629','20071106111629',DEFAULT,180,0);" << endl;
Any reason you're not using either template queries or SSQLS here?
MySQL++ will generate a lot of the most repetitive sorts of SQL for you,
if you let it.
> for(;;)
> {
> Query query = con.query();
This is hiding a variable of the same name outside the loop. You could
just be reset()ting the query object at the top of the loop instead.
> // 105 more UPDATEs with similar data
Why so many? I realize there's an overhead to each transaction, so the
more transactions you batch up in each query execution the better, but
the point of diminishing returns has to be well before this.
> if(kbhit())
> {
> cout << "Program halted by user\n";
>
> while(kbhit())
> char a=getch();
> exit(0);
> }
> }
Instead of this unportable DOS-era crappery, please consider this instead:
string s;
cin >> s;
It's not "Press any key", but it suffices. I say this not just because
of style reasons, but also because you're cutting off a big chunk of
your testing audience if you stick to these Windowsisms.