Rainer Hantsch wrote 20 lines
Hello, everybody!
Currently I am thinking about enhancing my MySQL unit, because it currently
does only a very simple way of querying. I use Michael's "mysql" unit and made
another "layer" on top of it, preventing me from doing too much particular
things repeatedly.
My biggest problem is that this mysql unit returns the data in form of an
array [0..n], which does not really make it easier to pick out a particular
field. So I want to write a function which gets a field name passed and
returns me the content. For that purpose I need to query the field names of a
table, but I do not know, HOW.
Can somebody help, please?
mfg
Ing. Rainer Hantsch
Take a look at mysql manual in section Mysql API - MySql C API u have list of functions with small examples - all u need. In your case U probably need function mysql_fetch_fields(...)
<FROM MANUAL>
8.4.3.16 mysql_fetch_fields()
MYSQL_FIELD *mysql_fetch_fields(MYSQL_RES *result) Description
Returns an array of all MYSQL_FIELD structures for a result set. Each structure provides the eld denition for one column of the result set. Return Values
An array of MYSQL_FIELD structures for all columns of a result set. Errors
None.
Example
unsigned int num_fields;
unsigned int i;
MYSQL_FIELD *fields;
num_fields = mysql_num_fields(result);
fields = mysql_fetch_fields(result);
for(i = 0; i < num_fields; i++)
{
printf("Field %u is %s\n", i, fields[i].name);
}
</FROM MANUAL>