Result Set Packets

You are viewing an old version of this article. View the current version here.

MariaDB Server sends the following packets as part of a result set: A resultset consists of different packets:



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:

  • int<lenenc> column count
  • if (MARIADB_CLIENT_CACHE_METADATA capability set)
    • int<1> metadata follows (0 / 1)

The metadata indicator byte is only present if both the client and the server declare the MARIADB_CLIENT_CACHE_METADATA capability.

If the metadata byte is set to 1, the normal metadata will follow the column definitions. If the metadata byte is set to 0, the Column Count Packet is immediately followed by the second EOF packet (EOF_Packet) or the resultset rows if the CLIENT_DEPRECATE_EOF capability is set.

Column Definition Packet

A column definition packet describes a column in the result set. It uses the following format:

Field types

The column type field in the column definition packet describes the base type of the column. It also indicates how the values are encoded for COM_STMT_EXECUTE parameters and binary resultset rows.

ValueProtocol Column TypeEncoding
0MYSQL_TYPE_DECIMALbyte<lenenc> encoding
1MYSQL_TYPE_TINYTINYINT Binary encoding
2MYSQL_TYPE_SHORTSMALLINT Binary encoding
3MYSQL_TYPE_LONGINTEGER Binary encoding
4MYSQL_TYPE_FLOATFLOAT Binary encoding
5MYSQL_TYPE_DOUBLEDOUBLE Binary encoding
6MYSQL_TYPE_NULLNot used, nullness is indicated by the NULL-bitmap in the result
7MYSQL_TYPE_TIMESTAMPTIMESTAMP Binary encoding
8MYSQL_TYPE_LONGLONGBIGINT Binary encoding
9MYSQL_TYPE_INT24INTEGER Binary encoding
10MYSQL_TYPE_DATETIMESTAMP Binary encoding
11MYSQL_TYPE_TIMETIME Binary encoding
12MYSQL_TYPE_DATETIMETIMESTAMP Binary encoding
13MYSQL_TYPE_YEARSMALLINT Binary encoding
14MYSQL_TYPE_NEWDATEbyte<lenenc> encoding
15MYSQL_TYPE_VARCHARbyte<lenenc> encoding
16MYSQL_TYPE_BITbyte<lenenc> encoding
17MYSQL_TYPE_TIMESTAMP2Used only in the replication protocol
18MYSQL_TYPE_DATETIME2Used only in the replication protocol
19MYSQL_TYPE_TIME2Used only in the replication protocol
245MYSQL_TYPE_JSONbyte<lenenc> encoding (only used with MySQL, MariaDB uses MYSQL_TYPE_STRING for JSON)
246MYSQL_TYPE_NEWDECIMALbyte<lenenc> encoding
247MYSQL_TYPE_ENUMbyte<lenenc> encoding
248MYSQL_TYPE_SETbyte<lenenc> encoding
249MYSQL_TYPE_TINY_BLOBbyte<lenenc> encoding
250MYSQL_TYPE_MEDIUM_BLOBbyte<lenenc> encoding
251MYSQL_TYPE_LONG_BLOBbyte<lenenc> encoding
252MYSQL_TYPE_BLOBbyte<lenenc> encoding
253MYSQL_TYPE_VAR_STRINGbyte<lenenc> encoding
254MYSQL_TYPE_STRINGbyte<lenenc> encoding
255MYSQL_TYPE_GEOMETRYbyte<lenenc> encoding

Field 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 ValueFlag NameFlag Description
1NOT_NULLfield cannot be null
2PRIMARY_KEYfield is a primary key
4UNIQUE_KEYfield is unique
8MULTIPLE_KEYfield is in a multiple key
16BLOBis this field a Blob
32UNSIGNEDis this field unsigned
64ZEROFILL_FLAGis this field a zerofill
128BINARY_COLLATIONwhether this field has a binary collation
256ENUMField is an enumeration
512AUTO_INCREMENTfield auto-increment
1024TIMESTAMPfield is a timestamp value
2048SETfield is a SET
4096NO_DEFAULT_VALUE_FLAGfield doesn't have default value
8192ON_UPDATE_NOW_FLAGfield is set to NOW on UPDATE
32768NUM_FLAGfield is num

The BLOB flag cannot be used to determine if a column has binary data, because BINARY and VARBINARY columns are treated as strings, instead of blobs.

The BINARY_COLLATION flag can be used to determine if a string column has binary data.

Extended metadata

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 be MYSQL_TYPE_GEOMETRY, but the extended type will indicate 'point'.
  • For a JSON column, the column type field will be MYSQL_TYPE_STRING, but the extended type will indicate 'json'.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.