From e178de2d66e5ff743457d800fd684d0ff3c9709e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Rowi=C5=84ski?= Date: Fri, 22 Jun 2018 10:41:07 +0200 Subject: [PATCH] Feature/next release (#43) * added checking for eof (#42) * adds support for column type 11 - TIME (mysql 5.5 only) (#41) --- CHANGELOG.md | 4 ++++ .../Definitions/ConstFieldType.php | 4 ++-- src/MySQLReplication/Event/Event.php | 7 +++++-- .../Event/RowEvent/RowEvent.php | 20 +++++++++++++++---- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d824902..42687be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ # Release Notes +## v5.0.2 (2018-06-22) +- Added checking for eof (#42) +- Added support for column type 11 - TIME (mysql 5.5 only) (#41) + ## v5.0.1 (2018-05-29) - Added tests now include php 7.2 and MariaDb 10.3 - Added truncate table test (#37) diff --git a/src/MySQLReplication/Definitions/ConstFieldType.php b/src/MySQLReplication/Definitions/ConstFieldType.php index 18583f8..ac05ea0 100644 --- a/src/MySQLReplication/Definitions/ConstFieldType.php +++ b/src/MySQLReplication/Definitions/ConstFieldType.php @@ -19,7 +19,7 @@ class ConstFieldType const LONGLONG = 8; const INT24 = 9; const DATE = 10; - const TIME = 11; + const TIME = 11; // MySQL 5.5 const DATETIME = 12; const YEAR = 13; const NEWDATE = 14; @@ -44,4 +44,4 @@ class ConstFieldType const INTERVAL = self::ENUM; const IGNORE = 666; -} \ No newline at end of file +} diff --git a/src/MySQLReplication/Event/Event.php b/src/MySQLReplication/Event/Event.php index 645f893..18521e7 100644 --- a/src/MySQLReplication/Event/Event.php +++ b/src/MySQLReplication/Event/Event.php @@ -28,6 +28,7 @@ class Event { const MARIADB_DUMMY_QUERY = '# Dum'; + const EOF_HEADER_VALUE = 254; /** * @var BinLogSocketConnect @@ -78,8 +79,10 @@ public function consume() { $binaryDataReader = new BinaryDataReader($this->binLogSocketConnect->getResponse()); - // "ok" value on first byte continue - $binaryDataReader->advance(1); + // check EOF_Packet -> https://dev.mysql.com/doc/internals/en/packet-EOF_Packet.html + if (self::EOF_HEADER_VALUE === $binaryDataReader->readUInt8()) { + return; + } // decode all events data $eventInfo = $this->createEventInfo($binaryDataReader); diff --git a/src/MySQLReplication/Event/RowEvent/RowEvent.php b/src/MySQLReplication/Event/RowEvent/RowEvent.php index 45a96c8..79c9812 100644 --- a/src/MySQLReplication/Event/RowEvent/RowEvent.php +++ b/src/MySQLReplication/Event/RowEvent/RowEvent.php @@ -12,7 +12,6 @@ use MySQLReplication\Event\DTO\UpdateRowsDTO; use MySQLReplication\Event\DTO\WriteRowsDTO; use MySQLReplication\Event\EventCommon; -use MySQLReplication\Event\EventException; use MySQLReplication\Event\EventInfo; use MySQLReplication\Exception\MySQLReplicationException; use MySQLReplication\JsonBinaryDecoder\JsonBinaryDecoderException; @@ -403,7 +402,6 @@ public function makeTableMapDTO() * @return WriteRowsDTO|null * @throws InvalidArgumentException * @throws BinaryDataReaderException - * @throws EventException * @throws JsonBinaryDecoderException * @throws MySQLReplicationException */ @@ -458,7 +456,6 @@ protected function rowInit() /** * @return array * @throws BinaryDataReaderException - * @throws EventException * @throws JsonBinaryDecoderException * @throws MySQLReplicationException */ @@ -566,6 +563,8 @@ protected function getColumnData($colsBitmap) $values[$name] = $this->getDatetime2($column); } else if ($column['type'] === ConstFieldType::TIMESTAMP) { $values[$name] = date('c', $this->binaryDataReader->readUInt32()); + } else if ($column['type'] === ConstFieldType::TIME) { + $values[$name] = $this->getTime(); } else if ($column['type'] === ConstFieldType::TIME2) { $values[$name] = $this->getTime2($column); } else if ($column['type'] === ConstFieldType::TIMESTAMP2) { @@ -917,7 +916,6 @@ protected function getBit(array $column) * @return DeleteRowsDTO * @throws InvalidArgumentException * @throws BinaryDataReaderException - * @throws EventException * @throws JsonBinaryDecoderException * @throws MySQLReplicationException */ @@ -986,4 +984,18 @@ protected function getEnum(array $column) return ''; } + + /** + * @return string + */ + protected function getTime() + { + $data = $this->binaryDataReader->readUInt24(); + + if (0 === $data) { + return '00-00-00'; + } + + return sprintf('%s%02d:%02d:%02d', $data < 0 ? '-' : '', $data / 10000, ($data % 10000) / 100, $data % 100); + } }