战魂小筑

讨论群:309800774 知乎关注:http://zhihu.com/people/sunicdavy 开源项目:https://github.com/davyxu

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  257 随笔 :: 0 文章 :: 506 评论 :: 0 Trackbacks

MySQL++在MySQL原始C接口上做了一些封装, 给操作带来很大便利.

最近遇到DB服务器中报出一个MySQL的错误:Commands out of sync; you can't run this command now,2014

查阅很多代码, 解决方法都是使用C接口的方式, 模仿其解决方法,在MySQL++中找到了比较好的解决方案:

方案A: 清空每次未使用的记录

for (int i = 1; DataQuery.more_results(); ++i)
{
   DataQuery.store_next();                
}

其中 DataQuery类型为mysqlpp::Query

 

方案B: 对于存储过程中,使用了多个select语句返回同样的列结果, 就需要使用以下语句

static void print_multiple_results(Query& query)
{
    // 执行查询并输出结果表
 StoreQueryResult res = query.store();
 print_result(res, 0);
 for (int i = 1; query.more_results(); ++i) {
  res = query.store_next();
  print_result(res, i);
 }
}
 
参考文章:http://hi.baidu.com/freeknight/item/ea9fd88e7d291f854514cf43
posted on 2012-06-13 17:57 战魂小筑 阅读(6689) 评论(0)  编辑 收藏 引用 所属分类: 网络 服务器技术C++/ 编程语言

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理