Resultset
Resultset
A resultset consists of different packets:
- Resultset metadata
- 1 Column count packet
- for each column (i.e column_count times)
- if not (CLIENT_DEPRECATE_EOF capability set) EOF_Packet
- n resultset row
- if error
- else
- if CLIENT_DEPRECATE_EOF capability
- OK_Packet with a 0xFE header
- else EOF_Packet
- if CLIENT_DEPRECATE_EOF capability
Resultset row can begin with 0xfe byte (when using text protocol with a field length > 0xffffff)
To ensure that packets beginning with 0xfe correspond to the ending packet (EOF_Packet or OK_Packet with a 0xFE header), the packet length must be checked and must be less than 0xffffff in length.
ResultSet metadata
Column count packet
- int<lenenc> column count
Column definition packet
- string<lenenc> catalog (always 'def')
- string<lenenc> schema
- string<lenenc> table alias
- string<lenenc> table
- string<lenenc> column alias
- string<lenenc> column
- if extended type supported (see MARIADB_CLIENT_EXTENDED_TYPE_INFO)
- int<lenenc> length extended info
- loop
- int<1> data type: 0x00:type, 0x01: format
- string<lenenc> value
- int<lenenc> length of fixed fields (=0xC)
- int<2> character set number
- int<4> max. column size
- int<1> Field types
- int<2> Field detail flag
- int<1> decimals
- int<2> - unused -
Field type permit to indicate storage type. Extended type information might indicate additional information.
Example for geometry data : field type will be MYSQL_TYPE_GEOMETRY meaning wkb encoding, but extended type might indicate 'point'.
Example for JSON data : field type will be MYSQL_TYPE_STRING as json are stored as String, extended format will indicate 'json'.
Field types
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 for mysql only |
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 |
Field detail flag
The field details flag will permit having an indication, like is this field signed ?
The blob flag is not enough to permit identifying if the field is a binary flag: char binary and varchar binary are not binary (they are handled like strings), but have the binary flag!
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 |