471,050 Members | 1,433 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,050 software developers and data experts.

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(&dbmaster, initial_query)) != 0) {
exit(1);
}
if ((master = mysql_store_result(&dbmaster)) == 0) {
exit(1);
}
if ((master_fields = mysql_fetch_fields(master)) == NULL) {
exit(1);
}
master_column = mysql_num_fields(master);
//master_column = mysql_field_count(&dbmaster);
mysql_free_result(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_fields or
mysql_field_count. 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.
Jul 19 '05 #1
2 3735
cs***@yahoo.com (James Lee) wrote in message news:<14**************************@posting.google. com>...
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(&dbmaster, initial_query)) != 0) {
exit(1);
}
if ((master = mysql_store_result(&dbmaster)) == 0) {
exit(1);
}
if ((master_fields = mysql_fetch_fields(master)) == NULL) {
exit(1);
}
master_column = mysql_num_fields(master);
//master_column = mysql_field_count(&dbmaster);
mysql_free_result(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_fields or
mysql_field_count. 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.


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.
Jul 19 '05 #2
cs***@yahoo.com (James Lee) wrote in message news:<14**************************@posting.google. com>...
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(&dbmaster, initial_query)) != 0) {
exit(1);
}
if ((master = mysql_store_result(&dbmaster)) == 0) {
exit(1);
}
if ((master_fields = mysql_fetch_fields(master)) == NULL) {
exit(1);
}
master_column = mysql_num_fields(master);
//master_column = mysql_field_count(&dbmaster);
mysql_free_result(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_fields or
mysql_field_count. 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.


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.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by James Lee | last post: by
7 posts views Thread by George Hester | last post: by
2 posts views Thread by Anthony Cuttitta Jr. | last post: by
reply views Thread by Kevin Spencer | last post: by
reply views Thread by Charles Leonard | last post: by
4 posts views Thread by Paul | last post: by
13 posts views Thread by SAL | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.