Problems with getting boolean from db

Hi,

I cannot get boolean data from MySQL database. This is how I tried to do that, assuming that conn is a valid connection:

1
2
3
4
5
6
7
8
9
MYSQL_RES *res; 
MYSQL_ROW row; 

mysql_query(conn, "SELECT name, sex FROM customers"); 
res = mysql_store_result(conn); 
while (row = mysql_fetch_row(res)) 
{ 
printf("%s\n", row[0]); 
}


The code above works fine for me, but it prints name fields only. If I try changing printf("%s\n", row[0]) to printf("%s\n", row[1]), it doesn't print the thing I need.

Field name is varchar, sex is bool. I'd like to know how can I get data from the sex field. I use Borland C++ 6 and MySQL C API for connecting.

Thanks in advance!
The number of values in the row is given by mysql_num_fields(result). If row holds the return value from a call to mysql_fetch_row(), pointers to the values are accessed as row[0] to row[mysql_num_fields(result)-1]. NULL values in the row are indicated by NULL pointers.

http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-row.html
Thanks kbw, I read that before. mysql_num_fields(res) returns 2, as it was supposed to be. But row[1] returns this: http://img28.imageshack.us/img28/6828/70502938.png Half of my listbox is empty, and another half is filled with those lines.
What's the field length? If the field isn't a string, it may be represented as a different type.
Sorry for my stupidity. I forgot that row[1] is always pointer to char. I changed it to row[1][0], and now it prints 0 or 1.

The problem is solved, thank you kbw for help!
Topic archived. No new replies allowed.