It seems that when I have one mysql_real_query () function in a continuous while loop, the query will be executed in order.
However, if multiple mysql_real_query () loops are inside the while loop, one by one. Depending on the request, sometimes the first request or the second request is not executed.
It seems to me that this is a problem with threads. I am wondering if mysql c api method has deal with this? Does anyone know how to deal with this? mysql_free_result () does not work, since I do not even save the results.
while(szRxChar != '-')
{
if (HasOverlappedIoCompleted(&ovRead))
{
if (!ReadFile(hSerial,&szRxChar,1,
&dwBytesRead,&ovRead))
{
DWORD dwErr = GetLastError();
if (dwErr!=ERROR_IO_PENDING)
return dwErr;
}
}
if (!(HasOverlappedIoCompleted(&ovRead)))
{
WaitForSingleObject(hReadEvent,RESET_TIME);
}
if (GetOverlappedResult(hSerial,&ovRead,
&dwBytesRead,FALSE))
{
GetOverlappedResult(hSerial,&ovWrite,
&dwBytesWritten,TRUE);
tagBuffer[i] = szRxChar;
i++;
tagBuffer[i] = 0;
if( strlen(tagBuffer)==PACKET_LENGTH )
{
sprintf(query,"insert into scan (rfidnum) values ('");
strcat(query, tagBuffer);
strcat(query, "')");
mysql_real_query(&mysql,query,(unsigned int)strlen(query));
i=0;
}
mysql_real_query(&mysql,"insert into scan (rfidnum) values ('2nd query')",(unsigned int)strlen("insert into scan (rfid) values ('2nd query')"));
mysql_free_result(res);
}
}
source
share