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. 20145227《Java程序设计》第2次实验报告

    20145227<Java程序设计>第2次实验报告 实验步骤与内容 一.实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 ...

  2. java 面试每日一题2

    题目:输入一行字符,分别统计出其中英文字母.空格.数字和其它字符的个数. 注:如果想单独输出中文的个数和中文符号的个数,只需把isChinese()中的if语句修改 知识补充: java不像C中拥有s ...

  3. xcode4.3 完成输入后 点击背景关闭键盘

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES];} 把这个复制到 ...

  4. 收藏的Android非常好用的组件或者框架。

    博客分类: android android框架 先说两个网站: http://www.androidviews.net/ http://www.theultimateandroidlibrary.co ...

  5. Reflector8.5 .net反编译工具 破解教程

    一.断网 二.打开软件.打开注册机 三. 四. 五. 六. 七. 八.

  6. A Plug for UNIX 分类: POJ 图论 函数 2015-08-10 14:18 2人阅读 评论(0) 收藏

    A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14786 Accepted: 4994 Desc ...

  7. 周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏

    Integration of Polynomial Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...

  8. 测试-ConstantForce的驱动方式以及是否穿透

    当我把FixedUpdate更新频率设置为1秒一次,测试结果如下: 结论: 1.由物理更新驱动 2.不会产生穿透

  9. MFC设置对话框大小

    设置对话框大小不可改变 1.在类的头文件中加入函数申明 (.h文件) afx_msg void OnGetMinMaxInfo(MINMAXINFO *lpMMI); 2.在消息映射中添加 (.cpp ...

  10. IDEA打war包

    一 第一步创建一个web application:expolded 选择当前项目 二 新建一个web application: Archive 选择刚刚新建的Expoded  “For ‘...... ...