List:MySQL++« Previous MessageNext Message »
From:Jordan Hewitt Date:January 16 2013 12:23am
Subject:Re: MySQL++ Query Loop : Commands Out of Sync?
View as plain text  
Yup, that would do it.  I realized what my problem was.  Inside 
tableExists(), I opened another query (to check if a table existed), so 
MySQL was complaining about the tableExists query, not the create table 
query.
Adding "IF NOT EXISTS" did wonders!  Thank you.

On Tue 15 Jan 2013 02:34:13 PM PST, Martin Gallwey wrote:
> Commands out of sync doesn't mean mysqlpp thinks you are executing the
> commands simultaneously, it is an error from MySQL itself:
>
> https://dev.mysql.com/doc/refman/5.0/en/commands-out-of-sync.html
>
> This stand-alone program of mine works fine:
>
> #include <mysql++/mysql++.h>
> #include <mysql++/query.h>
> #include <iostream>
> using namespace mysqlpp;
> using namespace std;
> int main ()
> {
>     Connection* g_pConnection = NULL;
>     g_pConnection = new Connection(...);
>
>     mysqlpp::Query query = g_pConnection->query();
>     const char *drop_q[] = {"DROP TABLE if exists `t1`;", "DROP TABLE
> if exists `t2`", "DROP TABLE if exists `t3`"};
>     const char *queries[] = {"CREATE TABLE t1 ( `id` int(11) NOT NULL
> );", "CREATE TABLE t2 ( `id` int(11) NOT NULL );", "CREATE TABLE t3
> (`id` int(11) NOT NULL )"};
>     const char *tables[] = {"t1", "t2", "t3"};
>     // sz = is the size of "queries"
>     for (size_t i = 0; i < sizeof queries / sizeof queries[0]; ++i)
>     {
>         query.reset();
>         if ( true ) //!tableExists(tables[i]))
>         {
>             cout << "Executing " << i << ", query: " <<
> drop_q[i] << endl;
>             query << drop_q[i];
>             query.execute();
>             cout << "Executing " << i << ", query: " <<
> queries[i] <<
> endl;
>             query << queries[i];
>             query.execute();
>         }
>     }
> }
>
> So I suspect the problem is in your tableExists function which isn't
> included in your email or pastebin. You could just change your queries
> to CREATE TABLE IF NOT EXISTS, rather than just 'CREATE TABLE'.
>
> On 15 January 2013 21:23, Jordan Hewitt <jordannh@stripped
> <mailto:jordannh@stripped>> wrote:
>
>     Here is my code: http://pastebin.com/A4Km6bcC
>     MySQL returns with: Commands out of sync; you can't run this
>     command now
>     t1 is created, but t2 is not.  For some reason MySQL++ thinks I'm
>     running the queries simultaneously.
>     Even if I do the following, I still get the error:
>
>       * Replace remove lines19-21
>       * After the if(!tableExists) {...} block, add the following lines:
>         query = NULL;
>         delete query;
>         query = connection.query();
>
>     If I do nothing to query, I still get the same error.  Any ideas?
>      I may
>     just go with the native MySQL.
>     Thanks.
>
>
Thread
MySQL++ Query Loop : Commands Out of Sync?Jordan Hewitt15 Jan
  • Re: MySQL++ Query Loop : Commands Out of Sync?Warren Young15 Jan
    • Re: MySQL++ Query Loop : Commands Out of Sync?Warren Young16 Jan
  • Re: MySQL++ Query Loop : Commands Out of Sync?Martin Gallwey15 Jan
    • Re: MySQL++ Query Loop : Commands Out of Sync?Jordan Hewitt16 Jan