我们正在运行一个C程序,其中每一秒都有一个函数回调。下面的代码列出的片段:C运行查询显示命令不同步?
char timeBuf[10],secondBuf1[100],queryBuf1[500],queryBuf2[500];
char buff[20] = {0};
struct timeval tv;
gettimeofday (&tv, NULL);
tv.tv_sec -= 5;
strftime(buff, 20, "%Y-%m-%d %H:%M:%S", localtime(&tv.tv_sec));
printf("\nTime is %s", buff);
sprintf(secondBuf1,"INSERT INTO secondsLog2 (secondLogID , timeStampID) VALUES (NULL,'%s')",buff);
//printf("Query 1 before executing %s\n",queryBuf1);
if (mysql_query(localConn, secondBuf1))
{
printf("Error in insert of seconds log %s\n",mysql_error(localConn));
exit(1);
}
sprintf(queryBuf1,"SELECT ipDest, portDest, SUM(packetLen), COUNT(ipDest) FROM source1 WHERE timeStamp = '%s' GROUP BY portDest",buff);
printf("\nQuery buf %s",queryBuf1);
if(mysql_query(remoteConn, queryBuf1))
{
printf("Error in first query of select %s\n",mysql_error(remoteConn));
exit(1);
}
localRes1 = mysql_use_result(remoteConn);
while((localRow1 = mysql_fetch_row(localRes1)) !=NULL)
{
sprintf(queryBuf1,"INSERT INTO export1 (iBTID ,timeStampID ,ipDest ,portDest,totalBits, packetCount) VALUES (NULL,'%s','%s','%s',%s,%s)",buff, localRow1[0],localRow1[1],localRow1[2],localRow1[3],localRow1[4]);
printf("Query 1 before executing %s\n",queryBuf1);
if (mysql_query(localConn, queryBuf1))
{
printf("Error in first query of insert %s\n",mysql_error(localConn));
exit(1);
}
}
mysql_free_result(localRes1);
我运行此脚本第二SELECT
会给我这个错误的时刻:命令不同步;你现在不能运行此命令:
Time is 2012-07-17 00:59:14
Query buf SELECT ipDest, portDest, SUM(packetLen), COUNT(ipDest) FROM source1 WHERE timeStamp = '2012-07-17 00:59:14' GROUP BY portDest
Time is 2012-07-17 00:59:15
Query buf SELECT ipDest, portDest, SUM(packetLen), COUNT(ipDest) FROM source1 WHERE timeStamp = '2012-07-17 00:59:15' GROUP BY portDestError in first query of select Commands out of sync; you can't run this command now
我已经更新了我的与被利用从之前的选择查询和INFACT我确实有这个了mysql_free_result(localRes1)的结果插入查询的问题;但是在插入查询之后。所以现在我应该在插入查询之前释放它,然后我将如何使用插入查询的结果? – user837306 2012-07-16 17:51:42
我试过这个localRes2 = localRes1;释放localRes1之前,但在插入语句中没有显示任何内容? – user837306 2012-07-16 17:56:43
所以最好解决我的插入问题以获得结果,以确保我的选择不再被卡住。我确实有mysql_store_result(remoteConn); ?那么,那么错误是什么? – user837306 2012-07-16 17:58:46