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. Greenplum的全量恢复之gpdbrestore

    gpdbrestore命令是对gp_restore命令的一个包装,提供了更灵活的选项,比如,使用gpcrondump自动备份的文件来恢复.使用gpdbrestore恢复必须具备: 1. 存在gpcro ...

  2. keepalived + nginx双主 实战

    安装nginx nginx 下载地址 http://nginx.org/download/nginx-1.8.0.tar.gz 安装nginx的依赖关系 yum install pcre pcre-d ...

  3. openlayers 学习笔记一

    1. 创建地图,加载控件 var map = new OpenLayers.Map("map", { projection: new OpenLayers.Projection(& ...

  4. cookie与localstorage和sessionstorage的区别比较

    保存位置: 三者均保存在浏览器端,且同源的. 与服务器的关系: cookie 数据始终在同源的http请求中携带(即使不需要),即cookie在浏览器和服务器间来回传递. sessionStorage ...

  5. 每日一九度之 题目1023:EXCEL排序

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:18804 解决:4240 题目描述:     Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能.     对每个测试用例 ...

  6. Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏

    Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...

  7. FTP操作类

    using System; using System.Collections.Generic; using System.Net; using System.IO; namespace HGFTP { ...

  8. Poj(1797) Dijkstra对松弛条件的变形

    题目链接:http://poj.org/problem?id=1797 题意:从路口1运货到路口n,最大的运货重量是多少?题目给出两路口间的最大载重. 思路:j加到s还是接到K下面,取两者的较大者,而 ...

  9. nylg 小M的因子和

    小M的因子和 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 小M在上课时有些得意忘形,老师想出道题目难住他.小M听说是求因子和,还是非常得意,但是看完题目是求A的B ...

  10. Mybaits 之根据集合查询和逗号分隔的子查询

    这是我们的mapper要根据传入一个集合进行查询: List<ExtKeywordCategory> findListByIds(List<ExtKeywordFkCategory& ...