MySQL问题一则:Commands out of sync; you can't run this comma(2)
但在实际测试中,还是出现问题:"Commands out of sync; you can't run this command now",我们的日志显示:
view sourceprint?
2011-11-07 15:01:28,660: INFO : Update OK!sql: insert into t_alarm_record_file (recordPath,recordName,hostIp,startTime,endTime,deviceId,programNumber,deviceType,interfaceNo,alarmType,alarmTime) values ('/figure/data/AlarmRecord/StreamTS/1-码流_魅力音 乐主路/2011-11-07/20111107150116.ts','','10.0.60.2','2011-11-07 15:01:16','1970-01-01 08:00:00',37486602,3905,'0',1,12,'2011-11-07 15:01:20');update t_alarm set fileId = LAST_INSERT_ID() where deviceId = 37486602 and programNumber = 3905 and alarmType = 12 and alarmDate = '2011-11-07 15:01:20' and fileId is null
2011-11-07 15:01:35,331: ERROR : Update failed!sql: insert into t_alarm_record_file (recordPath,recordName,hostIp,startTime,endTime,deviceId,programNumber,deviceType,interfaceNo,alarmType,alarmTime) values ('/figure/data/AlarmRecord/StreamTS/1-码流_魅力音 乐主路/2011-11-07/20111107150116.ts','','10.0.60.2','2011-11-07 15:01:16','1970-01-01 08:00:00',37486602,3905,'0',1,13,'2011-11-07 15:01:27');update t_alarm set fileId = LAST_INSERT_ID() where deviceId = 37486602 and programNumber = 3905 and alarmType = 13 and alarmDate = '2011-11-07 15:01:27' and fileId is null, ERROR:Commands out of sync; you can't run this command now
在第一次调用Update()执行多条sql语句时成功,但以后的所有调用都失败了。
经过查找,发现问题在于:在Update()中执行多条sql语句时,
如果仅仅是插入等不需要返回值的SQL语句,也一样得读完整个resault集并释放,最小化的写法:
do
{
result = mysql_store_result( mysql );
mysql_free_result(result);
}while( !mysql_next_result( mysql ) );
经过这么一处理,问题终于解决了。
作者:楚
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>