dbTalk Databases Forums  

Command out of sync error

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Command out of sync error in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kovacs Peter Tamas
 
Posts: n/a

Default Command out of sync error - 04-26-2005 , 10:40 AM






Hi,

I'm trying to code a small app that optimizes my tables every once every
day. If I give "optimize table xx " commands to the simple mysql client in
a row, everything is ok.

Here is a part of my my source, I think it should do the same:

// analyze and optimize tables
list<string> tableNames;

tableNames.push_back("fileok");
tableNames.push_back("gep_beallitasok");
tableNames.push_back("gep_login");
tableNames.push_back("gep_login_rootdir");
tableNames.push_back("gepek");
tableNames.push_back("konyvtar_alkonyvtar");
tableNames.push_back("konyvtarak");
tableNames.push_back("loginok");

for (list<string>::const_iterator i = tableNames.begin(); i != tableNames.end(); i++) {
Query query = con.query();
query << "optimize table " << *i;
cout << query.preview() << endl;
try {
query.execute();
}
catch (BadQuery e) {
cout << "BadQuery" << endl;
cout << e.error << endl;
}
catch (BadConversion e) {
cout << "BadConversion" << endl;
}
catch (BadNullConversion e) {
cout << "BadNullConversion" << endl;
}
}


But it doesn't. It gives me this error message:
Commands out of sync; you can't run this command now

A little googling gave me the meaning of this error message:
"If you get Commands out of sync; you can't run this command now in your
client code, you are calling client functions in the wrong order!

This can happen, for example, if you are using mysql_use_result() and try
to execute a new query before you have called mysql_free_result(). It can
also happen if you try to execute two queries that return data without a
mysql_use_result() or mysql_store_result() in between."

But I don't see what am I doing in the wrong order. My queries don't even
have results! What could be the problem?


Thanks for your kind help in advance,
Peter

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Kovacs Peter Tamas
 
Posts: n/a

Default Re: Command out of sync error - 04-26-2005 , 12:20 PM






Now I got the soultion from Jo Ellen:

If I use query.store() instead of query.execute(), put the results in a
Result and twrow them away, then it works correctly.

Thanks for the help again.

Peter

On Tue, 26 Apr 2005, Kovacs Peter Tamas wrote:

Quote:
Hi,

I'm trying to code a small app that optimizes my tables every once every
day. If I give "optimize table xx " commands to the simple mysql client in
a row, everything is ok.

Here is a part of my my source, I think it should do the same:

// analyze and optimize tables
list<string> tableNames;

tableNames.push_back("fileok");
tableNames.push_back("gep_beallitasok");
tableNames.push_back("gep_login");
tableNames.push_back("gep_login_rootdir");
tableNames.push_back("gepek");
tableNames.push_back("konyvtar_alkonyvtar");
tableNames.push_back("konyvtarak");
tableNames.push_back("loginok");

for (list<string>::const_iterator i = tableNames.begin(); i != tableNames.end(); i++) {
Query query = con.query();
query << "optimize table " << *i;
cout << query.preview() << endl;
try {
query.execute();
}
catch (BadQuery e) {
cout << "BadQuery" << endl;
cout << e.error << endl;
}
catch (BadConversion e) {
cout << "BadConversion" << endl;
}
catch (BadNullConversion e) {
cout << "BadNullConversion" << endl;
}
}


But it doesn't. It gives me this error message:
Commands out of sync; you can't run this command now

A little googling gave me the meaning of this error message:
"If you get Commands out of sync; you can't run this command now in your
client code, you are calling client functions in the wrong order!

This can happen, for example, if you are using mysql_use_result() and try
to execute a new query before you have called mysql_free_result(). It can
also happen if you try to execute two queries that return data without a
mysql_use_result() or mysql_store_result() in between."

But I don't see what am I doing in the wrong order. My queries don't even
have results! What could be the problem?


Thanks for your kind help in advance,
Peter

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...h (DOT) bme.hu


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.