#include #include #include int main(int argc, char **argv) { MYSQL *mysql = NULL; mysql = mysql_init(mysql); if (!mysql) { puts("Init faild, out of memory?"); return EXIT_FAILURE; } if (!mysql_real_connect(mysql, /* MYSQL structure to use */ "127.0.0.1", /* server hostname or IP address */ "root", /* mysql user */ "", /* password */ "test", /* default database to use, NULL for none */ 0, /* port number, 0 for default */ NULL, /* socket file or named pipe name */ CLIENT_FOUND_ROWS /* connection flags */ )) { puts("Connect failed\n"); } else { mysql_query(mysql, "SET NAMES utf8"); if (mysql_query(mysql, "SELECT LPAD(i, 7, ' ') as t FROM test.f LIMIT 1")) { printf("Query failed: %s\n", mysql_error(mysql)); } else { MYSQL_RES *result = mysql_store_result(mysql); if (!result) { printf("Couldn't get results set: %s\n", mysql_error(mysql)); } else { MYSQL_FIELD *fields; fields = mysql_fetch_fields(result); if (!fields) { printf("Faild fetching fields: %s\n", mysql_error(mysql)); } else { unsigned int i, num_fields = mysql_num_fields(result); for (i = 0; i < num_fields; i++) { printf("FIELD #%d\n", i); printf(" %-20s %s\n", "Field name", fields[i].name); printf(" %-20s %s\n", "Original name", fields[i].org_name); printf(" %-20s %s\n", "From table", fields[i].table); printf(" %-20s %s\n", "Original name", fields[i].org_table); printf(" %-20s %s\n", "Database", fields[i].db); printf(" %-20s %s\n", "Catalog", fields[i].catalog); printf(" %-20s %s\n", "Default", fields[i].def); printf(" %-20s %lu\n", "CREATE field length", fields[i].length); printf(" %-20s %lu\n", "MAX field lengt", fields[i].max_length); printf(" %-20s %u\n", "Field name length", fields[i].name_length); printf(" %-20s %u\n", "Original name length", fields[i].org_name_length); printf(" %-20s %u\n", "Table name length", fields[i].table_length); printf(" %-20s %u\n", "Original name length", fields[i].org_table_length); printf(" %-20s %u\n", "DB name length", fields[i].db_length); printf(" %-20s %u\n", "Catalog name length", fields[i].catalog_length); printf(" %-20s %u\n", "Default length", fields[i].def_length); printf(" %-20s %d: %s\n", "Charset", fields[i].charsetnr, get_charset_name(fields[i].charsetnr)); printf(" %-20s %u\n", "Field type", fields[i].type); printf(" %-20s %X\n", "Flags", fields[i].flags); /* TODO: decimals */ printf("\n"); } } } } } mysql_close(mysql); return EXIT_SUCCESS; }