[fpc-pascal]MySQL question...

Mirek Novak mirek.novak at auto.cz
Thu Jul 4 09:46:04 CEST 2002

Rainer Hantsch wrote:
> 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> mysql_fetch_fields()
   MYSQL_FIELD *mysql_fetch_fields(MYSQL_RES *result)
     Returns an array of all MYSQL_FIELD structures for a result set. Each structure provides
eld de
nition for one column of the result set.
   Return Values
     An array of MYSQL_FIELD structures for all columns of a result set.


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);

Mirek Novak
Anima Publishers
CMS development


jabber:mirek at njs.netlab.cz

More information about the fpc-pascal mailing list