使用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)的时候 ...
随机推荐
- [HTML]JS添加表格
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- YTU 3003: 括号匹配(栈和队列)
3003: 括号匹配(栈和队列) 时间限制: 1 Sec 内存限制: 128 MB 提交: 2 解决: 2 [提交][状态][讨论版] 题目描述 假设一个表达式中只允许包含三种括号:圆括号&quo ...
- Linux学习之八——利用变量
一.变量的使用 用$放在变量前面进行使用,例如: echo $PATH 为了和别的字符隔开,可以用{}和"",例如 echo ${PATH}nic echo "$PATH ...
- JQuery知识快览之一—选择器
阅读指导:本文参考最新的1.10.2版写成,针对用得比较多的1.4版,所有1.5版之后的函数都会注明哪一版新增.对于熟悉1.4版想学1.10版的请直接搜索"新增". JQuery是 ...
- 第十二届浙江省大学生程序设计大赛-Lunch Time 分类: 比赛 2015-06-26 14:30 5人阅读 评论(0) 收藏
Lunch Time Time Limit: 2 Seconds Memory Limit: 65536 KB The 999th Zhejiang Provincial Collegiate Pro ...
- VRRP配置与维护手册-1
http://www.gpxz.com/diannao/hulianwang/80526.html 一 VRRP简介< xmlnamespace prefix ="o" n ...
- jar 文件
使用类库中的类: 1.当前应用程序所在目录中没有包名的类,直接用. 2.java库. import语句导入. 3.当前目录的子孙目录有报名的类,set classpath,之前有写. 4.扩展ext文 ...
- C#字符串题目
老师给小学生门布置了一些作业,让它们按照一个模版写一些字符串交上来,同学们把作业交上来了,问题来了,这么多的作业老师批改不过来,现在请你帮老师写一个程序,帮助老师确定各个字符串是否合格.首先老师有一个 ...
- 通过PowerShell查看Android端log信息
在Windows下我们可以通过在cmd中输入adb logcat相关命令来查看安卓设备上的log信息,这在PowerShell里也可以做到.所以方便做成一个脚本,以便复用.代码如下: function ...
- SPRING官方网下载地址
SPRING官方网站改版后,建议都是通过 Maven和Gradle下载,对不使用Maven和Gradle开发项目的,下载就非常麻烦,下给出Spring Framework jar官方直接下载路径: h ...