Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Subject: Re: Issues with multi-queries

Subject: Re: Issues with multi-queries

2007-11-07       - By Warren Young

 Back
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.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:    http://lists.mysql.com/plusplus?unsub=mysql@(protected)