Changeset - e7e6ab77c542
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 16 years ago 2010-02-19 22:12:21
ohnobinki@ohnopublishing.net
various small mysql.c fixes
1 file changed with 7 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/server/mysql.c
Show inline comments
 
@@ -152,25 +152,26 @@ distrend_mysql_result_t mysqlQuery(distr
 

	
 
  /**
 
     pointless sanity check
 
  */
 
  if(conn->pointlesscheck != SEVENTY_FIVE)
 
    fprintf(stderr, "warning, I was passed a bad struct distrend_mysql_conn...\n");
 

	
 
  /** make sure that connection is still alive
 
   */
 
  
 
  if(mysql_ping(conn->mysqlconn))
 
    {
 
      fprintf(stderr, "MySQL connection broken, and reconnect is disabled!\n");
 
      fprintf(stderr, "mysql_ping() failed: %s\n", mysql_error(conn->mysqlconn));
 
      return NULL;
 
    }
 

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

	
 
  fprintf(stderr,"Getting results... ");
 
  result = mysql_use_result(conn->mysqlconn);
 
@@ -196,40 +197,45 @@ distrend_mysql_result_t mysqlQuery(distr
 
      
 
      mysql_free_result(result);
 
      return NULL;
 
    }
 
  fprintf(stderr,"Done!\n");
 

	
 
  /**
 
     Prepare data for return.
 
   */
 
  distrenresult = malloc(sizeof(struct distrend_mysql_result));
 
  if(!distrenresult)
 
    {
 
      while(mysql_fetch_row(result))
 
	;
 
      mysql_free_result(result);
 
      return NULL;
 
    }
 

	
 
  distrenresult->mysqlresult = result;
 
  distrenresult->pointlesscheck = FORTY_TWO;
 

	
 
  return distrenresult;
 
}
 

	
 
int mysqlResultFree(distrend_mysql_result_t result)
 
{
 
  size_t counter;
 

	
 
  if(!result)
 
    {
 
      fprintf(stderr, "mysqlResultFree(): warning, passed NULL parameter\n");
 
    return 0;
 
    }
 

	
 
  if(result->pointlesscheck != FORTY_TWO)
 
    fprintf(stderr, "%s:%d: I didn't get the type of handle I wanted\n", __FILE__, __LINE__);
 

	
 
  /**
 
     Must flush the resultset buffer.
 
   */
 
  for(counter = 0;
 
      mysql_fetch_row(result->mysqlresult);
 
      counter ++)
 
    ;
 
  if(counter)
0 comments (0 inline, 0 general)