1、代码如下:

void TestCache(otl_connect& otlConn)
{
try
{
char sql[] = {};
sprintf(sql,"call test1(1)");
otl_stream stream(, sql, otlConn,otl_implicit_select); int id;
while(!stream.eof())
{
stream>>id;
char sql2[] = {};
sprintf(sql2,"call test2(:Id<int>)");
otl_stream stream2(, sql2, otlConn,otl_implicit_select);
stream2<<id;
  
       int ff =0;
while(!stream2.eof())
{
stream2>>ff;
}
}
}
catch(otl_exception& ex)
{
printf("ExecuteSql Error, ErrorMsg[%s], Sql[%s]",
ex.msg,
ex.stm_text);
}
}

2、执行otl_stream stream2(100, sql2, otlConn,otl_implicit_select);的时候出错,如下:

Commands out of sync; you can't run this command now

特别注意:如果test1 只返回1条或者0条记录,不会导致这个异常。

3、错误原因:mysql上一次的查询没有将结果集释放掉,又进行下一次的查询。
4、otl:在第一个stream读取期间,第二个stream使用了绑定变量,会导致上面的问题,不知道otl内部是怎么封装的。
5、解决办法:
a、第二个stream不使用绑定变量,如下:

void TestCache(otl_connect& otlConn)
{
try
{
char sql[] = {};
sprintf(sql,"call test1(1)");
otl_stream stream(, sql, otlConn,otl_implicit_select); int id;
while(!stream.eof())
{
stream>>id;
char sql2[] = {};
sprintf(sql2,"call test2(%d)",id);
otl_stream stream2(, sql2, otlConn,otl_implicit_select); int ff =0;
while(!stream2.eof())
{
stream2>>ff;
}
}
}
catch(otl_exception& ex)
{
printf("ExecuteSql Error, ErrorMsg[%s], Sql[%s]",
ex.msg,
ex.stm_text);
}
}

b、先把第一个stream读取完,再进行第二个stream,如下:

void TestCache(otl_connect& otlConn)
{
try
{
char sql[] = {};
sprintf(sql,"call test1(1)");
otl_stream stream(, sql, otlConn,otl_implicit_select); vector<int> intVec;
int id;
while(!stream.eof())
{
stream>>id;
intVec.push_back(id);
} for(vector<int>::iterator iter = intVec.begin();
iter != intVec.end(); ++iter)
{
char sql2[] = {};
sprintf(sql2,"call test2(:Id<int>)");
otl_stream stream2(, sql2, otlConn,otl_implicit_select);
stream2<<id; int ff =0;
while(!stream2.eof())
{
stream>>ff;
}
}
}
catch(otl_exception& ex)
{
printf("ExecuteSql Error, ErrorMsg[%s], Sql[%s]",
ex.msg,
ex.stm_text);
}
}

使用otl,报错:mysql Commands out of sync; you can't run this command now的更多相关文章

  1. python mysql 2014 Commands out of sync; you can't run this command now

    这个问题出现再 mysql和c  的api. 简单的解决方法是不使用api直接把整个连接和命令传过去. 例如,cmd = 'mysql -h 192.168.32.210 -P 3316 -u bfd ...

  2. error:2014 Commands out of sync; you can't run this command now

    如下错误: 分析原因: 前端ajax请求后台,共用同一个链接. 搜索别人的解决方案:http://blog.csdn.net/grass_ring/article/details/3499402 用m ...

  3. C mysql (C API Commands out of sync; you can't run this command now)

    错误出现在当一个用户使用查询,另一个用户再使用此sql连接进行查询的时候: 原因是因为上一次使用此sql连接进行查询时没有将所有的结果集给释放掉,在所有使用此sql连接进行查询的地方将所有的结果集给释 ...

  4. _mysql_exceptions.ProgrammingError:(2014, "commands out of sync; you can't run this command now")

    今天,测试dashboard上的一些graph, 发现,当多个graph同时向后台请求数据(异步)的时候, 出现了上述错误.而且,三个bug交替出现,另外两个bug分别是:python stop re ...

  5. mysql_query error:Commands out of sync;you can't run this command now

    MYSQL_REST *result没有释放, 用mysql_free_result(result)即可.

  6. MySql: ”Commands out of sync“Error (Connect/C++)

    使用 Connector/C++ 查询 Mysql , 连续调用存储过程时 会出现如下: Commands out of sync; you can't run this command now,st ...

  7. mysql启动报错 mysql InnoDB: Error: could not open single-table tablespace file

    mysql启动不成功,报错 mysql InnoDB: Error: could not open single-table tablespace file innodb_force_recovery ...

  8. mysql 数据传输报错 MySQL server has gone away With statement:

    利用navicat premium 拷贝数据库时,报错MySQL server has gone away With statement:, 造成这样的原因一般是sql操作的时间过长,或者是传送的数据 ...

  9. MySQL Insert数据量过大导致报错 MySQL server has gone away

    接手了同事的项目,其中有一个功能是保存邮件模板(包含图片),同事之前的做法是把图片进行base64编码然后存在mysql数据库中(字段类型为mediumtext)然后保存三张图片(大概400k)的时候 ...

随机推荐

  1. POJ 1260:Pearls(DP)

    http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8 ...

  2. linux ar命令

    当我们的程序中有经常使用的模块,而且这种模块在其他程序中也会用到,这时按照软件重用的思想,我们应该将它们生成库,使得以后编程可以减少开发代码量.这里介绍命令ar,用来对库操作. 1.ar基本用法 ar ...

  3. Windows通过DOS命令进入MYSQL的方法

    例:MYSQL安装在 D:\ApacheServer\mysql 下 开始==>运行==>cmd,或者 按住win键+r键输入cmd C:\Users\Administrator>d ...

  4. 文本去重之MinHash算法

    1.概述     跟SimHash一样,MinHash也是LSH的一种,可以用来快速估算两个集合的相似度.MinHash由Andrei Broder提出,最初用于在搜索引擎中检测重复网页.它也可以应用 ...

  5. c#游戏 剪刀石头

    电脑using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace sh ...

  6. Unity脚本在层级面板中的执行顺序测试4-附加整理

    测试4为一些附加内容,后续的各种tips都加在此. 前几篇测试的链接: Unity脚本在层级面板中的执行顺序测试1 http://www.cnblogs.com/hont/p/4298110.html ...

  7. Github for Windows安装

    下载软件:https://desktop.github.com/ 安装之前要求系统先要有安装.net framework 4.5,不然软件安装的时候会自动上网下载安装,这软件下载起来非常慢. 第一次操 ...

  8. JAVAWeb使用POI做导出Excel

    一.需要了解的API ①HSSFWorkBook //代表一个Excel文件 ②HSSFSheet //代表一个表 ③HSSFRow //代表一个表中的某一行 ④HSSFCell //代表一个表中的某 ...

  9. 收集的55个Linux系统管理中常用的一些shell命令

    .显示消耗内存/CPU最多的10个进程 代码如下: | tail | tail .查看进程 按内存从大到小排列 代码如下: ps -e -o "%C : %p : %z : %a" ...

  10. CssSpritesGenerator使用

    最近一直在看CSS 的东西,在优化之路是哪个继续前进. 什么是css sprites css sprites直译过来就是CSS精灵,但是这种翻译显然是不够的,其实就是通过将多个图片融合到一副图里面,然 ...