#include #include #include static MYSQL_RES *my_query(MYSQL *conn, char *command) { MYSQL_RES *result; int rv; rv=mysql_query(conn,command); if(rv) { return NULL; } result=mysql_store_result(conn); if(!result) { return NULL; } return result; } int main(int argc, char *argv[]) { MYSQL *m=NULL; int field=0; if (argc < 2) { printf("Usage: %s [field]\n",argv[0]); exit(1); } if (argc == 3) { field = atoi(argv[2]); } m = mysql_init(NULL); m = mysql_real_connect(m,"localhost","root","XXXXXXXX","XXXXXXXX",0,NULL,0); if (m) { MYSQL_RES *res=NULL; char *query = argv[1]; res = my_query(m,query); if (res) { MYSQL_FIELD *f=NULL; printf("Fetch field: %d\n",field); f = mysql_fetch_field_direct(res,field); printf("char *name : %s\n",f->name); /* Name of column */ printf("char *table : %s\n",f->table); /* Table of column if column was a field */ printf("char *org_table : %s\n",f->org_table); /* Org table name if table was an alias */ printf("char *db : %s\n",f->db); /* Database for table */ printf("char *def : %s\n",f->def); /* Default value (set by mysql_list_fields) */ printf("unsigned long length : %lu\n",f->length); /* Width of column */ printf("unsigned long max_length: %lu\n",f->max_length);/* Max width of selected set */ printf("unsigned int flags : %u\n",f->flags); /* Div flags */ printf("unsigned int decimals : %u\n",f->decimals); /* Number of decimals in field */ printf("enum enum_field_types type: %d\n",f->type); /* Type of field. Se mysql_com.h for types */ mysql_free_result(res); } else { printf("ERROR: %s\n",mysql_error(m)); } mysql_close(m); } return 0; }