I wrote my first MySQL program in C last night. Seems to work pretty good.
However, for about 30 minutes, I was stuck attempting to output the returned data. I have a simple table
CREATE TABLE dbname.tbname (col1 INTEGER NOT NULL) ;
I inserted 50 rows in a loop and then selected the data:
SELECT * FROM dbname.tbname ORDER BY col1 ;
Upon fetching the rows,
Code:
// Get the handle for the result table
result_set = mysql_use_result(mysql) ;
if (!result_set) {
fprintf(stderr, "use_result failed. Error: %d, %s\n",
mysql_errno(mysql), mysql_error(mysql) ) ;
return -1 ;
}
else {
printf("Use Result worked!\n") ;
}
numcols = mysql_num_fields(result_set) ;
printf("There are %d columns in the result table.\n", numcols );
while ( row = mysql_fetch_row(result_set) ) {
for ( i = 0 ; i < numcols ; i++) {
printf("Row %d value = %s\n", i+1, row[i] );
}
}
I was expecting to get the data back in an integer field, but MySQL decided to convert the numeric data to strings! What's up with that? Is there an option, perhaps, to have it not do that?
Thanks