5.2 C API Basic Data Structures (original) (raw)

This section describes C API data structures other than those used for prepared statements, the asynchronous interface, or the replication stream interface. For information about those, seeSection 6.2, “C API Prepared Statement Data Structures”,Section 7.2, “C API Asynchronous Interface Data Structures”, andSection 10.2, “C API Binary Log Data Structures”.

The MYSQL_FIELD structure contains the members described in the following list. The definitions apply primarily for columns of result sets such as those produced bySELECT statements.MYSQL_FIELD structures are also used to provide metadata for OUT and INOUT parameters returned from stored procedures executed using preparedCALL statements. For such parameters, some of the structure members have a meaning different from the meaning for column values.

Tip

To view the MYSQL_FIELD member values for result sets interactively, start the mysql client with the --column-type-info option, then execute some sample queries.

if (field->flags & NOT_NULL_FLAG)  
    printf("Field cannot be null\n");  

You may use the convenience macros shown in the following table to determine the boolean status of theflags value.

Flag Status Description
IS_NOT_NULL(flags) True if this field is defined as NOT NULL
IS_PRI_KEY(flags) True if this field is a primary key
IS_BLOB(flags) True if this field is a BLOB orTEXT (deprecated; testfield->type instead)
mysql> SHOW COLLATION WHERE Id = 63;  
+-----------+---------+----+---------+----------+---------+  
| Collation | Charset | Id | Default | Compiled | Sortlen |  
+-----------+---------+----+---------+----------+---------+  
| binary    | binary  | 63 | Yes     | Yes      |       1 |  
+-----------+---------+----+---------+----------+---------+  
mysql> SELECT COLLATION_NAME, CHARACTER_SET_NAME  
       FROM INFORMATION_SCHEMA.COLLATIONS WHERE ID = 33;  
+-----------------+--------------------+  
| COLLATION_NAME  | CHARACTER_SET_NAME |  
+-----------------+--------------------+  
| utf8_general_ci | utf8               |  
+-----------------+--------------------+  
if (IS_NUM(field->type))  
    printf("Field is numeric\n");  

ENUM andSET values are returned as strings. For these, check that the type value is MYSQL_TYPE_STRING and that theENUM_FLAG or SET_FLAG flag is set in the flags value.