At 20:37 -0400 6/18/03, Andrew Pierce wrote:
I am trying to learn to use the C API for MySQL and have a question. I
have a table that has a primary key defined as int(11). I don't know what
data type this translates to in C. I thought maybe an unsigned int or an
unsigned long. I have this little loop that cycles through the results of
a query and displays the first two columns, the first being the int(11)
and the second a varchar. Here is the code:

result = mysql_use_result(&mysql);
while((row = mysql_fetch_row(result))) {
  printf("%lu %s\n", row[0], row[1]);
}

The first column is printed as garbage while the second column shows the
data correctly.

INT in MySQL is a 4-byte data type, but that's on the server side. The result that you're observing is that all values are returned to the *client* as strings. So you can either print the string using %s, or convert it to a C int and use %ld (you don't say that your MySQL type is UNSIGNED, so I'm assuming %ld rather than %lu).

The MySQL 4.1 client/server protocol has some features that allow you
to get back values in binary form without the conversion to string,
but you're probably not using that.


Help?


Thanks.

Andrew



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]


--
Paul DuBois, Senior Technical Writer
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

Are you MySQL certified? http://www.mysql.com/certification/


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to