【第22期】观点:IT 行业加班,到底有没有价值?

ERROR (ProgrammingError) (2014, "Commands out of sync; you can't run this command now")

原创 2016年05月31日 17:06:29

错误场景:

使用Python开发的数据库升级工具,在升级脚本行遇到如下语句报错了:

DROP TRIGGER IF EXISTS acl_2_ael_insert;
CREATE TRIGGER acl_2_ael_insert AFTER INSERT ON alarmclientlog
FOR EACH ROW 
UPDATE alarmeventlog SET alarm_deal_type = new.alarm_deal_type 
    WHERE alarmeventlog.strIndex = new.strIndex 
        AND alarmeventlog.strUniqueTime = new.strUniqueTime;

先解释下这段语句,alarmeventlog 表示原始报警日志,alarmclientlog 表示报警处理日志。当alarmclientlog 插入或更新后,要把处理结果也同步到alarmeventlog 里面去。
因此,我创建一个触发器做同步操作,为防止之前已经有此触发器,我先检查并删除下。


问题定位:

在网上搜到如下有用的资料:

Python’s MySQLdb 2014 Error – Commands out of sync
这里面说可能跟多条语句放在一起执行有关。

但是有些语句是可以放在一起执行的,那是不是对SQL语句的类型由要求?
然后我找到了这个帖子,是创建存储过程时发现的:
Python, “commands out of sync; you can’t run this command now”

这位也一样:
解决error:2014 Commands out of sync; you can’t run this command now

其他错误:
2014 - Commands out of sync; you can’t run this command now


解决问题:

综上所述,我感觉触发器、存储过程、SHOW等命令语句不能放一起执行。【待查】

解决方案是把语句分开执行。

在MySQL的官网手册,我发现了这个问题的说明:

B.5.2.14 Commands out of sync

If you get Commands out of sync; you can’t run this command now in
your client code, you are calling client functions in the wrong order.

This can happen, for example, if you are using mysql_use_result() and
try to execute a new query before you have called mysql_free_result().
It can also happen if you try to execute two queries that return
data without calling mysql_use_result() or mysql_store_result() in
between.

网址:B.5.2.14 Commands out of sync

版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

ERROR (ProgrammingError) (2014, "Commands out of sync; you can't run this command now")

错误场景:使用Python开发的数据库升级工具,在升级脚本行遇到如下语句报错了:DROP TRIGGER IF EXISTS acl_2_ael_insert; CREATE TRIGGER acl_...

Can't allocate space for object 'syslogs' in database 'ge' because 'logsegment' segment is full/has no free extents. If you ran out of space in syslogs, dump the transaction log. Otherwise, use ALTER

Can't allocate space for object 'syslogs' in database 'ge' because 'logsegment' segment is full/has no free extents. If you ran out of space in syslogs, dump the transaction log. Otherwise, use ALTER

欢迎关注CSDN程序人生公众号

关注程序员生活,汇聚开发轶事。

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

error:2014 Commands out of sync; you can't run this command now 原因有三: 其一、PrepareStatement中返回了多...

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

Q: i m getting this bug.. and i still cant understand why this happening..?? here is my php code <?php $query1 = "call new_user('$cardDigits','$cardNo','$amount','$traiff','','','','','$creator',@_lastname,'$customer','$firstName

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

C语言调用MySQL API中,使用mysql_query执行存储过程时,易产生该错误。解决方法是:在接收到结果集后,使用while(mysql_next_result(&mysql) == 0);深...
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)