mysql_fetch_fields issue

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

    #1

    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.
  • James Lee

    #2
    MySQL Bug (Was Re: mysql_fetch_fie lds issue)

    csejl@yahoo.com (James Lee) wrote in message news:<146277ca. 0310091912.503f 2ef7@posting.go ogle.com>...[color=blue]
    > 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.[/color]

    I have come to a conclusion that this is a bug in MySQL. It doesn't
    fetch the fields right if there are more than one column. Also, even
    if there is only one column it doesn't store the right information to
    MYSQL_FIELD struct, for example, type. Any comments? BTW,
    master_fields is of type MYSQL_FIELD *. Thanks.

    -j.

    Comment

    • James Lee

      #3
      MySQL Bug (Was Re: mysql_fetch_fie lds issue)

      csejl@yahoo.com (James Lee) wrote in message news:<146277ca. 0310091912.503f 2ef7@posting.go ogle.com>...[color=blue]
      > 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.[/color]

      I have come to a conclusion that this is a bug in MySQL. It doesn't
      fetch the fields right if there are more than one column. Also, even
      if there is only one column it doesn't store the right information to
      MYSQL_FIELD struct, for example, type. Any comments? BTW,
      master_fields is of type MYSQL_FIELD *. Thanks.

      -j.

      Comment

      Working...