Пример #1
0
int do_reconnects(char *sql) {
int m0, m1, m2 = 0, i;

//sql="select table_name from all_tables";

m0 =  m1 = os_mem_used();
//int do_smth=0;
//fprintf(stderr," start reconnects with mem %d  KB\n", m1/1024);
for(i=1;i<100*1000;i++) {
 db_done(db); // clear prev
 if (!db_connect_string(db,cs)) {
   fprintf(stderr,"-reconnect failed on %d step err=%s\n",i,db->error);
   msleep(1000); continue;
   //return 0;
   }
if (sql) {
 if (!db_select(db,sql)) {
   fprintf(stderr,"-select failed on step %d err=%s\n",i,db->error);
   return 0;
   }
 //while(db_fetch(db)); // Fetch all
 }
 m2 = os_mem_used();
 printf(" .. reconnect: %d mem_used: %d KB  delta= %d Bytes          \r",i,m2/1024, (m2-m1));
 if (i%100==0) { m1=m2; printf("\n"); }
 }
fprintf(stderr,"+%d reconnects done, leak: %d\n",i, (m2-m0));
return 0;
}
Пример #2
0
int main(int argc, char *argv[])
{
  MYSQL *mysql = db_init(WEIXIND_DB_HOST, WEIXIND_DB_PORT,
                         WEIXIND_DB_USER, WEIXIND_DB_PASSWD,
                         WEIXIND_DB_DB);
  if (mysql == NULL) {
    fprintf(stderr, "db_init failed\n");
    return -1;
  }
  db_done(mysql);
  return 0;
}