Documentation Home
MySQL Internals Manual
Download this Manual
EPUB - 0.8Mb


MySQL Internals Manual  /  ...  /  Binary Protocol Value

14.7.3 Binary Protocol Value

ProtocolBinary::MYSQL_TYPE_STRING, ProtocolBinary::MYSQL_TYPE_VARCHAR, ProtocolBinary::MYSQL_TYPE_VAR_STRING, ProtocolBinary::MYSQL_TYPE_ENUM, ProtocolBinary::MYSQL_TYPE_SET, ProtocolBinary::MYSQL_TYPE_LONG_BLOB, ProtocolBinary::MYSQL_TYPE_MEDIUM_BLOB, ProtocolBinary::MYSQL_TYPE_BLOB, ProtocolBinary::MYSQL_TYPE_TINY_BLOB, ProtocolBinary::MYSQL_TYPE_GEOMETRY, ProtocolBinary::MYSQL_TYPE_BIT, ProtocolBinary::MYSQL_TYPE_DECIMAL, ProtocolBinary::MYSQL_TYPE_NEWDECIMAL:
Fields

value (lenenc_str) -- string

Example
03 66 6f 6f -- string = "foo"

Todo. provide example for ProtocolBinary::MYSQL_TYPE_DECIMAL and ProtocolBinary::MYSQL_TYPE_NEWDECIMAL

ProtocolBinary::MYSQL_TYPE_LONGLONG
Fields

value (8) -- integer

Example
01 00 00 00 00 00 00 00 -- int64 = 1
ProtocolBinary::MYSQL_TYPE_LONG, ProtocolBinary::MYSQL_TYPE_INT24:
Fields

value (4) -- integer

Example
01 00 00 00 -- int32 = 1
ProtocolBinary::MYSQL_TYPE_SHORT, ProtocolBinary::MYSQL_TYPE_YEAR:
Fields

value (2) -- integer

Implemented By

Field_year::send_binary() and Protocol_binary::store_short()

Example
01 00 -- int16 = 1
ProtocolBinary::MYSQL_TYPE_TINY:
Fields

value (1) -- integer

Example
01 -- int8 = 1
ProtocolBinary::MYSQL_TYPE_DOUBLE:

MYSQL_TYPE_DOUBLE stores a floating point in IEEE 754 double precision format

first byte is the last byte of the significant as stored in C.

Fields

value (string.fix_len) -- (len=8) double

Example
66 66 66 66 66 66 24 40 -- double = 10.2
ProtocolBinary::MYSQL_TYPE_FLOAT:

MYSQL_TYPE_FLOAT stores a floating point in IEEE 754 single precision format

Fields

value (string.fix_len) -- (len=4) float

Example
33 33 23 41 -- float = 10.2
ProtocolBinary::MYSQL_TYPE_DATE, ProtocolBinary::MYSQL_TYPE_DATETIME, ProtocolBinary::MYSQL_TYPE_TIMESTAMP:

type to store a DATE, DATETIME and TIMESTAMP fields in the binary protocol.

to save space the packet can be compressed:

  • if year, month, day, hour, minutes, seconds and micro_seconds are all 0, length is 0 and no other field is sent

  • if hour, minutes, seconds and micro_seconds are all 0, length is 4 and no other field is sent

  • if micro_seconds is 0, length is 7 and micro_seconds is not sent

  • otherwise length is 11

Fields
  • length (1) -- number of bytes following (valid values: 0, 4, 7, 11)

  • year (2) -- year

  • month (1) -- month

  • day (1) -- day

  • hour (1) -- hour

  • minute (1) -- minutes

  • second (1) -- seconds

  • micro_second (4) -- micro-seconds

Example
0b da 07 0a 11 13 1b 1e 01 00 00 00 -- datetime 2010-10-17 19:27:30.000 001
04 da 07 0a 11                      -- date = 2010-10-17
0b da 07 0a 11 13 1b 1e 01 00 00 00 -- timestamp
Implemented By

Protocol_binary::store()

ProtocolBinary::MYSQL_TYPE_TIME:

type to store a TIME field in the binary protocol.

to save space the packet can be compressed:

  • if days, hours, minutes, seconds and micro_seconds are all 0, length is 0 and no other field is sent

  • if micro_seconds is 0, length is 8 and micro_seconds is not sent

  • otherwise length is 12

Fields
  • length (1) -- number of bytes following (valid values: 0, 8, 12)

  • is_negative (1) -- (1 if minus, 0 for plus)

  • days (4) -- days

  • hours (1) -- hours

  • minutes (1) -- minutes

  • seconds (1) -- seconds

  • micro_seconds (4) -- micro-seconds

Example
0c 01 78 00 00 00 13 1b 1e 01 00 00 00 -- time  -120d 19:27:30.000 001
08 01 78 00 00 00 13 1b 1e             -- time  -120d 19:27:30
01                                     -- time     0d 00:00:00
Implemented By

Protocol_binary::store_time()

ProtocolBinary::MYSQL_TYPE_NULL:

stored in the NULL-bitmap only


User Comments
Sign Up Login You must be logged in to post a comment.