Changeset - 3479dcafbf12
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 16 years ago 2010-02-19 21:35:14
ohnobinki@ohnopublishing.net
Better handle error situations, properly set MYSQL_OPT_RECONNECT
1 file changed with 14 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/server/mysql.c
Show inline comments
 
@@ -93,6 +93,8 @@ int mysqlConnect(distrend_mysql_conn_t *
 
  char *password = "HwLxuBqTvJ6J7FWj";
 
  char *database = "distren";
 

	
 
  my_bool mybool;
 

	
 
  mysqlconn = mysql_init(NULL);
 

	
 
  if(!mysql_real_connect(mysqlconn, server, user, password, database, 0, NULL, CLIENT_MULTI_STATEMENTS))
 
@@ -101,7 +103,11 @@ int mysqlConnect(distrend_mysql_conn_t *
 
      return 1;
 
    }
 

	
 
  mysql_options(mysqlconn, MYSQL_OPT_RECONNECT,"true"); // After mysql_real_connect due to bug fixed in MySQL 5.1.6 and later
 
  /**
 
     Called after mysql_real_connect() due to bug fixed in MySQL 5.1.6 and later
 
  */
 
  mybool = 1;
 
  mysql_options(mysqlconn, MYSQL_OPT_RECONNECT, (char *)&mybool);
 

	
 

	
 
  *conn = malloc(sizeof(struct distrend_mysql_conn));
 
@@ -154,12 +160,16 @@ distrend_mysql_result_t mysqlQuery(distr
 
   */
 
  
 
  if(mysql_ping(conn->mysqlconn))
 
    {
 
    fprintf(stderr, "MySQL connection broken, and reconnect is disabled!\n");
 

	
 
    }
 

	
 
  fprintf(stderr,"Querying... ");
 
  if (mysql_query(conn->mysqlconn, query))
 
     fprintf(stderr, "%s\n", mysql_error(conn->mysqlconn));
 
    {
 
      fprintf(stderr, "calling mysql_query() resulted in: %s\n", mysql_error(conn->mysqlconn));
 
      return NULL;
 
    }
 
  fprintf(stderr,"Queried!\n");
 

	
 
  fprintf(stderr,"Getting results... ");
 
@@ -223,7 +233,7 @@ int mysqlResultFree(distrend_mysql_resul
 
      counter ++)
 
    ;
 
  if(counter)
 
    fprintf(stderr, "Calling function did not flush all of the rows it should've\n");
 
    fprintf(stderr, "Calling function did not flush %d rows\n", (int)counter);
 

	
 
  mysql_free_result(result->mysqlresult);
 
  free(result);
0 comments (0 inline, 0 general)