//gcc bug42490.c -Wall -g -o bug42490 -L/home/sbester/build/mysql/5.1/mysql-5.1.30-linux-i686-glibc23/lib -I/home/sbester/build/mysql/5.1/mysql-5.1.30-linux-i686-glibc23/include -lmysqlclient_r -lz -lm -lpthread #include #include #include #include #include #include #include char host[]="127.0.0.1"; int port=3306; char username[]="root"; char password[]=""; char database[]="test"; int ps_func_0000(MYSQL *db); int main(int argc, const char *argv[]) { MYSQL *dbc=NULL; my_init(); if (!(dbc = mysql_init(NULL))) { printf("mysql_init failed\n"); return 1; } else { if (!mysql_real_connect(dbc,host,username,password,database,port, NULL, CLIENT_FOUND_ROWS|CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS)) { printf("mysql_real_connect failed: %s (%d) (%s)\n", mysql_error(dbc),mysql_errno(dbc),mysql_sqlstate(dbc)); mysql_close(dbc); return 1; } } printf("client version=%lu (%s)\n",mysql_get_client_version(),mysql_get_client_info()); printf("server version=%lu\n",mysql_get_server_version(dbc)); ps_func_0000(dbc); mysql_close(dbc); return 0; } int ps_func_0000(MYSQL *db) { //char *query="select ?"; char *query="show processlist"; MYSQL_STMT *stmt=NULL; int cnt,cols=0; MYSQL_RES *prepare_meta_result=NULL; stmt= mysql_stmt_init(db); if (NULL == stmt) { printf("[ps_func_0000] mysql_stmt_init failed: %s (%d) (%s)\n",mysql_error(db),mysql_errno(db),mysql_sqlstate(db)); goto end; } if(mysql_stmt_prepare(stmt,query,(unsigned long)strlen(query))) { printf("[ps_func_0000] mysql_stmt_prepare failed: %s (%d) (%s)\n",mysql_stmt_error(stmt),mysql_stmt_errno(stmt),mysql_stmt_sqlstate(stmt)); goto end; } prepare_meta_result = mysql_stmt_result_metadata(stmt); if(NULL == prepare_meta_result) { printf("[ps_func_0000] mysql_stmt_result_metadata returned null\n"); goto end; } cols=mysql_num_fields(prepare_meta_result); printf("[ps_func_0000] resultset will contain %d columns\n",cols); printf("\n\n"); for(cnt=0;cntname); printf("fields[%lu].table = %s\n",(unsigned long)cnt,field->table); printf("fields[%lu].db = %s\n",(unsigned long)cnt,field->db); printf("fields[%lu].length = %lu\n",(unsigned long)cnt,(unsigned long)field->length); printf("fields[%lu].max_length = %lu\n",(unsigned long)cnt,(unsigned long)field->max_length); printf("fields[%lu].type = %lu\n",(unsigned long)cnt,(unsigned long)field->type); printf("fields[%lu].org_name = %s\n",(unsigned long)cnt,field->org_name); printf("fields[%lu].org_table = %s\n",(unsigned long)cnt,field->org_table); printf("fields[%lu].catalog = %s\n",(unsigned long)cnt,field->catalog); printf("fields[%lu].def = %s\n",(unsigned long)cnt,field->def); printf("fields[%lu].name_length = %lu\n",(unsigned long)cnt,(unsigned long)field->name_length); printf("fields[%lu].org_name_length = %lu\n",(unsigned long)cnt,(unsigned long)field->org_name_length); printf("fields[%lu].table_length = %lu\n",(unsigned long)cnt,(unsigned long)field->table_length); printf("fields[%lu].org_table_length = %lu\n",(unsigned long)cnt,(unsigned long)field->org_table_length); printf("fields[%lu].db_length = %lu\n",(unsigned long)cnt,(unsigned long)field->db_length); printf("fields[%lu].catalog_length = %lu\n",(unsigned long)cnt,(unsigned long)field->catalog_length); printf("fields[%lu].def_length = %lu\n",(unsigned long)cnt,(unsigned long)field->def_length); printf("fields[%lu].flags = %lu\n",(unsigned long)cnt,(unsigned long)field->flags); printf("fields[%lu].decimals = %lu\n",(unsigned long)cnt,(unsigned long)field->decimals); printf("fields[%lu].charsetnr = %lu\n",(unsigned long)cnt,(unsigned long)field->charsetnr); printf("\n\n"); } mysql_free_result(prepare_meta_result); end: if(NULL != stmt && mysql_stmt_close(stmt)) { printf("[ps_func_0000] mysql_stmt_close failed: %s (%d) (%s)\n",mysql_stmt_error(stmt),mysql_stmt_errno(stmt),mysql_stmt_sqlstate(stmt)); } return 0; }