Bug #73127 mysql_real_query and reconnect
Submitted: 26 Jun 2014 19:17 Modified: 22 Aug 2014 11:06
Reporter: USER USER Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / C Severity:S2 (Serious)
Version: OS:Any
Assigned to: CPU Architecture:Any

[26 Jun 2014 19:17] USER USER
Description:
 NETWORK UP
 RUM App

 Call - mysql_real_query 
 k[0], mysql_real_query -OK- 
 Call - mysql_real_query 
 k[1], mysql_real_query -OK- 
  NETWORK DOWN
 Call - mysql_real_query  
 Call - mysql_real_query 
 Call - mysql_real_query   
 NETWORK UP
 k[2], mysql_real_query -OK- 
 Call - mysql_real_query 
 k[3], mysql_real_query -OK- 
  NETWORK DOWN
 Call - mysql_real_query 
 Call - mysql_real_query 
 Call - mysql_real_query 
  NETWORK UP
 k[4], mysql_real_query -OK- 

 k[5], COUNT[6] -OK- 

 mysql_real_query_OK = 5 , INSERT_ROW_COUNT = 6

How to repeat:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <mysql.h>
#include <errmsg.h>

int main(void)
{
  MYSQL *MySqLHandlE = NULL;
  MYSQL_RES *MySqLStoreResult = NULL;
  MYSQL_ROW MySqLFetchRow;

  my_bool do_reconnect = 1;
  unsigned int CONNECT_TIMEOUT = 10;
  unsigned int READ_TIMEOUT = 10;
  unsigned int WRITE_TIMEOUT = 10;
  
  unsigned char k = 0;
  
  const char ip[] = "localhost";
  unsigned int port = 3306;
  const char db[] = "DB";
  const char user[] = "USER";
  const char pass[] = "PASS";
  
  const char query00[] = "CREATE TABLE IF NOT EXISTS `TestTB0000` (`k` INT) ENGINE = InnoDB";
  const char query01[] = "INSERT INTO `TestTB0000` (`k`) VALUES (1)";
  const char query02[] = "SELECT COUNT(*) as `f0` FROM `TestTB0000`";
  const char query03[] = "DROP TABLE IF EXISTS `TestTB0000`";
  
  mysql_library_init(0, NULL, NULL);
  MySqLHandlE = mysql_init(NULL);
  mysql_options(MySqLHandlE, MYSQL_OPT_RECONNECT, &do_reconnect);
  mysql_options(MySqLHandlE, MYSQL_OPT_CONNECT_TIMEOUT, &CONNECT_TIMEOUT);
  mysql_options(MySqLHandlE, MYSQL_OPT_READ_TIMEOUT, &READ_TIMEOUT);
  mysql_options(MySqLHandlE, MYSQL_OPT_WRITE_TIMEOUT, &WRITE_TIMEOUT);
  mysql_real_connect(MySqLHandlE, ip, user, pass, db, port, NULL, CLIENT_NO_SCHEMA | CLIENT_REMEMBER_OPTIONS | CLIENT_MULTI_STATEMENTS);
  mysql_autocommit(MySqLHandlE, 1);
  
  mysql_real_query(MySqLHandlE, query03, strlen(query03)); 
  mysql_free_result(mysql_store_result(MySqLHandlE));
  mysql_real_query(MySqLHandlE, query00, strlen(query00)); 
  mysql_free_result(mysql_store_result(MySqLHandlE));

 k = 0;
 while(k < 5)
 {
  do {fprintf(stdout,"\n Call - mysql_real_query \n");} while(mysql_real_query(MySqLHandlE, query01, strlen(query01)) != 0);
  mysql_free_result(mysql_store_result(MySqLHandlE));
  
  fprintf(stdout,"\n k[%d], mysql_real_query -OK- \n", k); 
  sleep(5);
  k++;
 }

 mysql_real_query(MySqLHandlE, query02, strlen(query02));
 MySqLStoreResult = mysql_store_result(MySqLHandlE);
 MySqLFetchRow = mysql_fetch_row(MySqLStoreResult);
 
 fprintf(stdout,"\n k[%d], COUNT[%ld] -OK- \n", k, atol(MySqLFetchRow[0]));
 
 mysql_free_result(MySqLStoreResult);
 
 mysql_real_query(MySqLHandlE, query03, strlen(query03)); 
 mysql_free_result(mysql_store_result(MySqLHandlE));
 
  mysql_close(MySqLHandlE); MySqLHandlE = NULL;
  mysql_library_end();
  
 return(0);
}
[3 Jul 2014 16:26] MySQL Verification Team
Isn't this duplicate of Bug #73107?
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely to be the same. Because of this, we hope you add your comments to the original bug instead.

Thank you for your interest in MySQL.
[4 Aug 2014 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[22 Aug 2014 8:31] USER USER
...