首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

请问mysql++有关问题,commands out of sync

2012-02-25 
请教mysql++问题,commands out of sync我用mysql++ api来操作mysql数据库,部分大致程序如下:Connection co

请教mysql++问题,commands out of sync
我用mysql++ api来操作mysql数据库,
部分大致程序如下:
  Connection con;
  con.set_option(new MultiStatementsOption(true));
  if (!con.connect(mysqlpp::examples::db_name, cmdline.server(),
  cmdline.user(), cmdline.pass())) {
  return 1; }

  string str = "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;";

  Query query = con.query();
  StoreQueryResult res = query.store();

这个程序段会杯多次执行,第一次执行时正常,但第二次执行时报query异常,“commands out of sync,you can't run this command now”。

请高手指教。

[解决办法]
由于你是多条sql语句一次执行,因此必须把StoreQueryResult取尽才能执行下一次sql
看看能不能用query.store() != null不断取出再关闭。

热点排行