# Result Set Row

A result set row represents a database result set unit, which is usually generated by executing a statement that queries the database. Using [COM\_STMT\_EXECUTE](https://mariadb.com/docs/server/reference/clientserver-protocol/3-binary-protocol-prepared-statements/com_stmt_execute), the result set row is in binary format, otherswise in text format.

## Text Result Set Row

* For each column:
  * [string\<lenenc>](https://mariadb.com/docs/server/reference/protocol-data-types#length-encoded-strings) column data.

The byte representation of the string according to [client character collation](https://mariadb.com/docs/server/reference/clientserver-protocol/1-connecting/connection).

## Binary Result Set Row

* byte<1> `0x00` header.
* byte<(number\_of\_columns + 7) / 8> [NULL-Bitmap](#null-bitmap-values).
* For each column:
  * If column value is not null:
    * If `MYSQL_TYPE_DOUBLE` type : [DOUBLE Binary encoding](#double-binary-encoding)
    * If `MYSQL_TYPE_LONGLONG` type : [BIGINT Binary encoding](#bigint-binary-encoding)
    * If `MYSQL_TYPE_INTEGER` type : [INTEGER Binary encoding](#integer-binary-encoding)
    * If `MYSQL_TYPE_MEDIUMINT` type : [MEDIUMINT Binary encoding](#mediumint-binary-encoding)
    * If `MYSQL_TYPE_FLOAT` type : [FLOAT Binary encoding](#float-binary-encoding)
    * If `MYSQL_TYPE_SMALLINT` type : [SMALLINTBinary encoding](#smallint-binary-encoding)
    * If `MYSQL_TYPE_YEAR` type : [YEAR Binary encoding](#year-binary-encoding)
    * If `MYSQL_TYPE_TINYINT` type : [TINYINT Binary encoding](#tinyint-binary-encoding)
    * If `MYSQL_TYPE_DATE` type : [DATE Binary encoding](#date-binary-encoding)
    * If `MYSQL_TYPE_TIMESTAMP` type : [TIMESTAMP Binary encoding](#timestamp-binary-encoding)
    * If `MYSQL_TYPE_DATETIME` type : [TIMESTAMP Binary encoding](#timestamp-binary-encoding)
    * If `MYSQL_TYPE_TIME` type : [TIME Binary encoding](#time-binary-encoding)
    * If `MYSQL_TYPE_NEWDECIMAL` type : [DECIMAL Binary encoding](#decimal-binary-encoding)
    * If `MYSQL_TYPE_TINY_BLOB`, `MYSQL_TYPE_MEDIUM_BLOB`, `MYSQL_TYPE_LONG_BLOB`, `MYSQL_TYPE_BLOB`, `MYSQL_TYPE_GEOMETRY`, `MYSQL_TYPE_STRING`, `MYSQL_TYPE_VARCHAR`, `MYSQL_TYPE_VAR_STRING`): [byte\<lenenc>](https://mariadb.com/docs/server/reference/protocol-data-types#length-encoded-bytes) value

## NULL-Bitmap Values

The `NULL`-Bitmap indicates if a parameter for a column is null (one bit per parameter) beginning with the 3rd bit. `NULL`-bitmap size is (number\_of\_columns + 7) / 8.

## DECIMAL Binary Encoding

`DECIMAL` has no fixed size, so will be encoded as [string\<lenenc>](https://mariadb.com/docs/server/reference/protocol-data-types#length-encoded-strings). A `DECIMAL(10,2)` with a value of `-15.5` is stored as:

```
06 45 49 53 46 53 48      . - 1 5 . 5 0
```

## DOUBLE Binary Encoding

`DOUBLE` is the IEEE 754 floating-point value in Little-endian format on 8 bytes.

## BIGINT Binary Encoding

`BIGINT` is the value in Little-endian format on 8 bytes. Signed is defined by the [Column field detail flag](https://mariadb.com/docs/server/reference/clientserver-protocol/4-server-response-packets/result-set-packets).

## INTEGER Binary Encoding

`INTEGER` is the value in Little-endian format on 4 bytes. Signed is defined by the [Column field detail flag](https://mariadb.com/docs/server/reference/clientserver-protocol/4-server-response-packets/result-set-packets).

## MEDIUMINT Binary Encoding

`MEDIUMINT` is similar to `INTEGER` binary encoding, even if `MEDIUM` int is 3-bytes encoded server side. (Last byte will always be 0x00).

## FLOAT Binary Encoding

`FLOAT` is the IEEE 754 floating-point value in Little-endian format on 4 bytes.

## SMALLINT Binary Encoding

`SMALLINT` is the value in Little-endian format on 2 bytes. Signed is defined by the [Column field detail flag](https://mariadb.com/docs/server/reference/clientserver-protocol/4-server-response-packets/result-set-packets).

## YEAR Binary Encoding

`YEAR` uses the same format as `SMALLINT`.

## TINYINT Binary Encoding

`TINYINT` is the value of 1 byte. Signed is defined by the [Column field detail flag](https://mariadb.com/docs/server/reference/clientserver-protocol/4-server-response-packets/result-set-packets).

## DATE Binary Encoding

`DATE` uses the same format as `TIMESTAMP` binary encoding, with a data length of `0` for the special '`0000-00-00`' value and `4` for the standard year/month/day format.

## TIMESTAMP Binary Encoding

Data is encoded in 8 bytes without fractional seconds, 12 bytes with fractional seconds.

| Byte Position | Description                                                                                                                                                             |
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 1             | data length : 0 for special '0000-00-00 00:00:00' value. 4 with year + month + day of month only 7 for timestamps without fractional seconds 11 with fractional seconds |
| 2-3           | year on 2 bytes little-endian format                                                                                                                                    |
| 4             | Month ( 1=january)                                                                                                                                                      |
| 5             | days of month                                                                                                                                                           |
| 6             | hour of day (0 if DATE type)                                                                                                                                            |
| 7             | minutes (0 if DATE type)                                                                                                                                                |
| 8             | seconds (0 if DATE type)                                                                                                                                                |
| 9-12          | micro-second on 4 bytes little-endian format (only if data-length is > 7)                                                                                               |

## TIME Binary Encoding

Data is encoded in 9 bytes without fractional seconds, 13 bytes with fractional seconds.

* [int<1>](https://mariadb.com/docs/server/reference/protocol-data-types#fixed-length-integers) data length: 0 for special '00:00:00' value, 8 without fractional seconds, 12 with fractional seconds.
* If data length > `0`:
  * [int<1>](https://mariadb.com/docs/server/reference/protocol-data-types#fixed-length-integers) `0` for positive time, `1` for negative time.
  * [int<4>](https://mariadb.com/docs/server/reference/protocol-data-types#fixed-length-integers) days.
  * [int<1>](https://mariadb.com/docs/server/reference/protocol-data-types#fixed-length-integers) hours.
  * [int<1>](https://mariadb.com/docs/server/reference/protocol-data-types#fixed-length-integers) minutes.
  * [int<1>](https://mariadb.com/docs/server/reference/protocol-data-types#fixed-length-integers) seconds.
  * if data length > `8` :
    * [int<4>](https://mariadb.com/docs/server/reference/protocol-data-types#fixed-length-integers) microseconds.

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}
