title: multiple mysql_real_query() in while loop
body: <p>It seems that when I have one mysql_real_query() function in a continuous while loop, the query will get executed OK.</p>
  
  <p>However, if multiple mysql_real_query() are inside the while loop, one right after the other.  Depending on the query, sometimes neither the first query nor second query will execute properly.</p>
  
  <p>This seems like a threading issue to me. I'm wondering if the mysql c api has a way of dealing with this?   Does anyone know how to deal with this?   mysql_free_result() doesn't work since I am not even storing the results.</p>
  
  <pre><code>//keep polling as long as stop character '-' is not read
  while(szRxChar != '-')
  {
      // Check if a read is outstanding
      if (HasOverlappedIoCompleted(&amp;ovRead))
      {
          // Issue a serial port read
          if (!ReadFile(hSerial,&amp;szRxChar,1,
                  &amp;dwBytesRead,&amp;ovRead))
          {
              DWORD dwErr = GetLastError();
              if (dwErr!=ERROR_IO_PENDING)
                  return dwErr;
          }
      }
  
      // Wait 5 seconds for serial input
      if (!(HasOverlappedIoCompleted(&amp;ovRead)))
      {
          WaitForSingleObject(hReadEvent,RESET_TIME);
      }
  
      // Check if serial input has arrived
      if (GetOverlappedResult(hSerial,&amp;ovRead,
              &amp;dwBytesRead,FALSE))
      {
          // Wait for the write
          GetOverlappedResult(hSerial,&amp;ovWrite,
              &amp;dwBytesWritten,TRUE);
  
          //load tagBuffer with byte stream
          tagBuffer[i] = szRxChar;
          i++;
          tagBuffer[i] = 0; //char arrays are \0 terminated
  
          //run query with tagBuffer
          if( strlen(tagBuffer)==PACKET_LENGTH )
          {
              sprintf(query,"insert into scan (rfidnum) values ('");
              strcat(query, tagBuffer);
              strcat(query, "')");
              mysql_real_query(&amp;mysql,query,(unsigned int)strlen(query));
  
              i=0;
          }
  
          mysql_real_query(&amp;mysql,"insert into scan (rfidnum) values ('2nd query')",(unsigned int)strlen("insert into scan (rfid) values ('2nd query')"));
  
          mysql_free_result(res);
      }
  }
  </code></pre>