mysql_fetch_fields issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James Lee

    mysql_fetch_fields issue

    Hi,

    Somebody please help me. I have a table like this:

    ----------------
    column1|column2 |
    ---------------
    1 | 2 |
    ----------------

    Both columns are type int(11). And here's what I do:

    sprintf(initial _query, "%s %s LIMIT 1", select * from", tablename);

    if ((return = mysql_query(&db master, initial_query)) != 0) {
    exit(1);
    }
    if ((master = mysql_store_res ult(&dbmaster)) == 0) {
    exit(1);
    }
    if ((master_fields = mysql_fetch_fie lds(master)) == NULL) {
    exit(1);
    }
    master_column = mysql_num_field s(master);
    //master_column = mysql_field_cou nt(&dbmaster);
    mysql_free_resu lt(master);

    for (i=0; i<master_column ; i++) {
    printf ("field %d type is %d", i, master_fields[i].type);
    printf ("field %d name is %s", i, master_fields[i].name);
    }

    This is just a snippet. Every variable is declared correctly. Here,
    as expected, I get 2 as the return value for mysql_num_field s or
    mysql_field_cou nt. However, in the for loop, I get weird values for
    field type and get NULL for second column name:

    Field 0 type is 134557680 Field 0 name is column1
    Field 1 type is 3239533 Field 1 name is (null)

    WHAT IS GOING ON? I am at a loss. Could this be a bug in MySQL? I'd
    appreciate it if someone can shed some light on this? Thanks!

    -j.
Working...