List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:November 9 2007 11:03pm
Subject:Re: Issues with multi-queries
View as plain text  
Paul Martin wrote:
> 1. Comment out 4 lines starting with 'print_result' in the 
> 'print_multiple_results' function (to kill screen printing)

You also commented out the Query::more_results() call.  That's why it 
dies the second time around: you must consume all results on a MySQL DB 
connection before you make another one.  Hard limit of the underlying C 
API, no option to change it.  You must consume the results.

I made my own changes to multiquery.cpp, and it works here on both Linux 
and Windows, built against MySQL 5.0 and MySQL++ svn.

Index: examples/multiquery.cpp
===================================================================
--- examples/multiquery.cpp (revision 1814)
+++ examples/multiquery.cpp (working copy)
@@ -123,10 +123,10 @@
     try {
         // Execute query and print all result sets
         Result res = query.store();
-       print_result(res, 0);
-       for (int i = 1; query.more_results(); ++i) {
+       cout << '.' << flush;
+       while (query.more_results()) {
             res = query.store_next();
-           print_result(res, i);
+           cout << '.' << flush;
         }
     }
     catch (Exception& err) {
@@ -163,16 +163,18 @@

         // Set up query with multiple queries.
         Query query = con.query();
-       query << "DROP TABLE IF EXISTS test_table;" << endl <<
-               "CREATE TABLE test_table(id INT);" << endl <<
-               "INSERT INTO test_table VALUES(10);" << endl <<
-               "UPDATE test_table SET id=20 WHERE id=10;" << endl <<
-               "SELECT * FROM test_table;" << endl <<
-               "DROP TABLE test_table" << endl;
-       cout << "Multi-query: " << endl << query.preview() <<
endl;
+       while (1) {
+           query.reset();
+           query << "DROP TABLE IF EXISTS test_table; " <<
+                   "CREATE TABLE test_table(id INT); " <<
+                   "INSERT INTO test_table VALUES(10); " <<
+                   "UPDATE test_table SET id=20 WHERE id=10; " <<
+                   "SELECT * FROM test_table; " <<
+                   "DROP TABLE test_table";

-       // Execute statement and display all result sets.
-       print_multiple_results(query);
+           // Execute statement and display all result sets.
+           print_multiple_results(query);
+       }

  #if MYSQL_VERSION_ID >= 50000
         // If it's MySQL v5.0 or higher, also test stored procedures, which


It'll sit there spitting dots out at you until you get quite bored.
Thread
Issues with multi-queriesPaul Martin7 Nov
  • Re: Issues with multi-queriesWarren Young7 Nov
  • Re: Issues with multi-queriesPaul Martin7 Nov
    • Re: Issues with multi-queriesWarren Young7 Nov
  • Re: Issues with multi-queriesPaul Martin8 Nov
    • Re: Issues with multi-queriesWarren Young8 Nov
      • Re: Issues with multi-queriesMaarten Schrijvers8 Nov
  • Re: Issues with multi-queriesPaul Martin8 Nov
    • Re: Issues with multi-queriesWarren Young10 Nov
  • Re: Issues with multi-queriesPaul Martin10 Nov
    • Re: Issues with multi-queriesWarren Young10 Nov
  • RE: Issues with multi-queriesIan Daysh12 Nov
    • Re: Issues with multi-queriesWarren Young13 Nov