使用otl,报错:mysql Commands out of sync; you can't run this command now
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的更多相关文章
- 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 ...
- error:2014 Commands out of sync; you can't run this command now
如下错误: 分析原因: 前端ajax请求后台,共用同一个链接. 搜索别人的解决方案:http://blog.csdn.net/grass_ring/article/details/3499402 用m ...
- C mysql (C API Commands out of sync; you can't run this command now)
错误出现在当一个用户使用查询,另一个用户再使用此sql连接进行查询的时候: 原因是因为上一次使用此sql连接进行查询时没有将所有的结果集给释放掉,在所有使用此sql连接进行查询的地方将所有的结果集给释 ...
- _mysql_exceptions.ProgrammingError:(2014, "commands out of sync; you can't run this command now")
今天,测试dashboard上的一些graph, 发现,当多个graph同时向后台请求数据(异步)的时候, 出现了上述错误.而且,三个bug交替出现,另外两个bug分别是:python stop re ...
- mysql_query error:Commands out of sync;you can't run this command now
MYSQL_REST *result没有释放, 用mysql_free_result(result)即可.
- MySql: ”Commands out of sync“Error (Connect/C++)
使用 Connector/C++ 查询 Mysql , 连续调用存储过程时 会出现如下: Commands out of sync; you can't run this command now,st ...
- 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 ...
- mysql 数据传输报错 MySQL server has gone away With statement:
利用navicat premium 拷贝数据库时,报错MySQL server has gone away With statement:, 造成这样的原因一般是sql操作的时间过长,或者是传送的数据 ...
- MySQL Insert数据量过大导致报错 MySQL server has gone away
接手了同事的项目,其中有一个功能是保存邮件模板(包含图片),同事之前的做法是把图片进行base64编码然后存在mysql数据库中(字段类型为mediumtext)然后保存三张图片(大概400k)的时候 ...
随机推荐
- 【转】卸载VMware时提示“The MSI failed”解决方案
转载地址: http://www.2cto.com/os/201309/243843.html 安装精简版VM后再安装其他版本的VM,或者想升级安装更高的版本时,无法正常卸载(如提示The MSI ...
- Java与.NET 的Web Services相互调用
一:简介 本文介绍了Java与.NET开发的Web Services相互调用的技术.本文包括两个部分,第一部分介绍了如何用.NET做客户端调用Java写的Web Services,第二部分介绍了如何用 ...
- JQuery的$(document).ready(function(){})与JS的window.onload 的各自优势!
由于项目需要,使用JQuery也有相当一段时间了.由于经常要处理DOM节点加载.图片显示以及动态资源请求,所以对$(document).ready(function(){})理解也越来越深了,所有在此 ...
- Linux高级变量
http://blog.chinaunix.net/uid-27040051-id-3450991.html 高级变量 基本形式 [1].变量扩展 格式 ${变量名称} [2].命令扩展 格式 $(命 ...
- 给用户添加sudo权限
centos中默认创建的新用户是没有sudo权限的. 在文件/etc/sudoers中添加即可: ## Allow root to run any commands anywhere root ALL ...
- PHP比较运算!=和!==
PHP!=和!==的区别 !==是指绝对不等于,比如,$a = 3, $b="3" 那么,$a!==$b成立,可是$a!=$b不成立:
- linux 关机重启命令
1 shutdown 关机 shutdown -h now 立刻重启 -c 取消前面的一个关机命令 shutdown -c shotdown -r now 尽量使用shutdown 其余的关机命令 h ...
- Mysql-学习笔记(==》存储过程 九)
1.存储过程概念在大型数据库系统中,一组为了完成特定功能的sql语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它. 2.建立存储过程delimit ...
- Eclipse搭建Android5.0应用开发环境 “ndk-build”:launchingfailed问题解决
Eclipse搭建Android5.0应用开发环境 "ndk-build":launchingfailed问题解决 详细参考http://blog.csdn.net/loongem ...
- MSM8909平台 LED背光的控制
之前齐师兄问我,是不是应该有一个文件记录背光灯的亮度,我说理论上有,但是在哪里我真的还没有见过.只知道在调LCD驱动的时候会调用一个背光控制的函数,传进来一个亮度值就可以配置亮度了,至于这个函数是谁调 ...