Result Set Packets
Contents
MariaDB Server sends the following packets as part of a result set:
- The server sends the column count packet.
- For each column, the server sends the column definition packet.
- If the client did not set the
CLIENT_DEPRECATE_EOF
capability, then the server sends an EOF packet (EOF_Packet). - For each row, the server sends a result-set row packet (ResultsetRow).
If an error occurs, then an error packet (ERR_Packet) is sent.
Otherwise, the terminating packet depends on whether the client set the CLIENT_DEPRECATE_EOF
capability:
- If the client did not set the
CLIENT_DEPRECATE_EOF
capability, then the server sends an OK packet (OK_Packet) with a 0xFE header. - Otherwise, the server sends an EOF packet (EOF_Packet).
It would be unsafe to assume that any packet with a 0xFE header is an OK packet (OK_Packet) or an EOF packet (EOF_Packet), because result-set row packets (ResultsetRow) can also begin with 0xFE when using the text protocol with a field length greater than 0xFFFFFF.
To safely confirm that a packet with a 0xFE header is an OK packet (OK_Packet) or an EOF packet (EOF_Packet), you must also check that the packet length is less than 0xFFFFFF.
Column Count Packet
The column count packet describes the number of columns in the result set. It uses the following format:
Field Type | Field Description |
---|---|
int<lenenc> | Number of columns |
Column Definition Packet
A column definition packet describes a column in the result set. It uses the following format:
Field Type | Field Description |
---|---|
string<lenenc> | catalog (always 'def') |
string<lenenc> | schema |
string<lenenc> | table alias |
string<lenenc> | table |
string<lenenc> | column alias |
string<lenenc> | column |
Extended column type | Extended details about the column's type. Added in MariaDB 10.5.2. |
int<lenenc> | length of fixed fields (=0xC) |
int<2> | character set number |
int<4> | max. column size |
int<1> | Column type |
int<2> | Column details flag |
int<1> | decimals |
int<2> | Unused |
Column Types
The column type field in the column definition packet describes the base type of the column:
Value | Protocol Column Type | Description |
---|---|---|
0 | MYSQL_TYPE_DECIMAL | |
1 | MYSQL_TYPE_TINY | |
2 | MYSQL_TYPE_SHORT | |
3 | MYSQL_TYPE_LONG | |
4 | MYSQL_TYPE_FLOAT | |
5 | MYSQL_TYPE_DOUBLE | |
6 | MYSQL_TYPE_NULL | |
7 | MYSQL_TYPE_TIMESTAMP | |
8 | MYSQL_TYPE_LONGLONG | |
9 | MYSQL_TYPE_INT24 | |
10 | MYSQL_TYPE_DATE | |
11 | MYSQL_TYPE_TIME | |
12 | MYSQL_TYPE_DATETIME | |
13 | MYSQL_TYPE_YEAR | |
14 | MYSQL_TYPE_NEWDATE | |
15 | MYSQL_TYPE_VARCHAR | |
16 | MYSQL_TYPE_BIT | |
17 | MYSQL_TYPE_TIMESTAMP2 | |
18 | MYSQL_TYPE_DATETIME2 | |
19 | MYSQL_TYPE_TIME2 | |
245 | MYSQL_TYPE_JSON | Only used with MySQL. MariaDB uses MYSQL_TYPE_STRING for JSON. |
246 | MYSQL_TYPE_NEWDECIMAL | |
247 | MYSQL_TYPE_ENUM | |
248 | MYSQL_TYPE_SET | |
249 | MYSQL_TYPE_TINY_BLOB | |
250 | MYSQL_TYPE_MEDIUM_BLOB | |
251 | MYSQL_TYPE_LONG_BLOB | |
252 | MYSQL_TYPE_BLOB | |
253 | MYSQL_TYPE_VAR_STRING | |
254 | MYSQL_TYPE_STRING | |
255 | MYSQL_TYPE_GEOMETRY |
Extended Column Types
In MariaDB 10.5.2 and later, the server supports the MARIADB_CLIENT_EXTENDED_TYPE_INFO
capability. If a client sets the MARIADB_CLIENT_EXTENDED_TYPE_INFO
capability, then the server can provide extended type information for columns.
The extended column type information is preceded with the length of the section:
Field Type | Field Description |
---|---|
int<lenenc> | Length of extended column type information |
Next the following two fields are repeated until the specified length has been reached:
Field Type | Field Description |
---|---|
int<1> | data type: 0x00:type, 0x01: format |
string<lenenc> | value |
This extended column type information can be used to find out more specific details about the column type.
For example:
- For a
POINT
column, the column type field will beMYSQL_TYPE_GEOMETRY
, but the extended type will indicate 'point'. - For a
JSON
column, the column type field will beMYSQL_TYPE_STRING
, but the extended type will indicate 'json'.
Column Details Flag
The column details flag describes certain column attributes and whether certain column options are set.
It is a bitmask with the following flags:
Flag Value | Flag Name | Flag Description |
---|---|---|
1 | NOT_NULL | field cannot be null |
2 | PRIMARY_KEY | field is a primary key |
4 | UNIQUE_KEY | field is unique |
8 | MULTIPLE_KEY | field is in a multiple key |
16 | BLOB | is this field a Blob |
32 | UNSIGNED | is this field unsigned |
64 | ZEROFILL_FLAG | is this field a zerofill |
128 | BINARY_COLLATION | whether this field has a binary collation |
256 | ENUM | Field is an enumeration |
512 | AUTO_INCREMENT | field auto-increment |
1024 | TIMESTAMP | field is a timestamp value |
2048 | SET | field is a SET |
4096 | NO_DEFAULT_VALUE_FLAG | field doesn't have default value |
8192 | ON_UPDATE_NOW_FLAG | field is set to NOW on UPDATE |
32768 | NUM_FLAG | field is num |