Skip to content

Commit e178de2

Browse files
authored
Feature/next release (#43)
* added checking for eof (#42) * adds support for column type 11 - TIME (mysql 5.5 only) (#41)
1 parent 45c32f3 commit e178de2

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
# Release Notes
44

5+
## v5.0.2 (2018-06-22)
6+
- Added checking for eof (#42)
7+
- Added support for column type 11 - TIME (mysql 5.5 only) (#41)
8+
59
## v5.0.1 (2018-05-29)
610
- Added tests now include php 7.2 and MariaDb 10.3
711
- Added truncate table test (#37)

src/MySQLReplication/Definitions/ConstFieldType.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ConstFieldType
1919
const LONGLONG = 8;
2020
const INT24 = 9;
2121
const DATE = 10;
22-
const TIME = 11;
22+
const TIME = 11; // MySQL 5.5
2323
const DATETIME = 12;
2424
const YEAR = 13;
2525
const NEWDATE = 14;
@@ -44,4 +44,4 @@ class ConstFieldType
4444
const INTERVAL = self::ENUM;
4545

4646
const IGNORE = 666;
47-
}
47+
}

src/MySQLReplication/Event/Event.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
class Event
2929
{
3030
const MARIADB_DUMMY_QUERY = '# Dum';
31+
const EOF_HEADER_VALUE = 254;
3132

3233
/**
3334
* @var BinLogSocketConnect
@@ -78,8 +79,10 @@ public function consume()
7879
{
7980
$binaryDataReader = new BinaryDataReader($this->binLogSocketConnect->getResponse());
8081

81-
// "ok" value on first byte continue
82-
$binaryDataReader->advance(1);
82+
// check EOF_Packet -> https://dev.mysql.com/doc/internals/en/packet-EOF_Packet.html
83+
if (self::EOF_HEADER_VALUE === $binaryDataReader->readUInt8()) {
84+
return;
85+
}
8386

8487
// decode all events data
8588
$eventInfo = $this->createEventInfo($binaryDataReader);

src/MySQLReplication/Event/RowEvent/RowEvent.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use MySQLReplication\Event\DTO\UpdateRowsDTO;
1313
use MySQLReplication\Event\DTO\WriteRowsDTO;
1414
use MySQLReplication\Event\EventCommon;
15-
use MySQLReplication\Event\EventException;
1615
use MySQLReplication\Event\EventInfo;
1716
use MySQLReplication\Exception\MySQLReplicationException;
1817
use MySQLReplication\JsonBinaryDecoder\JsonBinaryDecoderException;
@@ -403,7 +402,6 @@ public function makeTableMapDTO()
403402
* @return WriteRowsDTO|null
404403
* @throws InvalidArgumentException
405404
* @throws BinaryDataReaderException
406-
* @throws EventException
407405
* @throws JsonBinaryDecoderException
408406
* @throws MySQLReplicationException
409407
*/
@@ -458,7 +456,6 @@ protected function rowInit()
458456
/**
459457
* @return array
460458
* @throws BinaryDataReaderException
461-
* @throws EventException
462459
* @throws JsonBinaryDecoderException
463460
* @throws MySQLReplicationException
464461
*/
@@ -566,6 +563,8 @@ protected function getColumnData($colsBitmap)
566563
$values[$name] = $this->getDatetime2($column);
567564
} else if ($column['type'] === ConstFieldType::TIMESTAMP) {
568565
$values[$name] = date('c', $this->binaryDataReader->readUInt32());
566+
} else if ($column['type'] === ConstFieldType::TIME) {
567+
$values[$name] = $this->getTime();
569568
} else if ($column['type'] === ConstFieldType::TIME2) {
570569
$values[$name] = $this->getTime2($column);
571570
} else if ($column['type'] === ConstFieldType::TIMESTAMP2) {
@@ -917,7 +916,6 @@ protected function getBit(array $column)
917916
* @return DeleteRowsDTO
918917
* @throws InvalidArgumentException
919918
* @throws BinaryDataReaderException
920-
* @throws EventException
921919
* @throws JsonBinaryDecoderException
922920
* @throws MySQLReplicationException
923921
*/
@@ -986,4 +984,18 @@ protected function getEnum(array $column)
986984

987985
return '';
988986
}
987+
988+
/**
989+
* @return string
990+
*/
991+
protected function getTime()
992+
{
993+
$data = $this->binaryDataReader->readUInt24();
994+
995+
if (0 === $data) {
996+
return '00-00-00';
997+
}
998+
999+
return sprintf('%s%02d:%02d:%02d', $data < 0 ? '-' : '', $data / 10000, ($data % 10000) / 100, $data % 100);
1000+
}
9891001
}

0 commit comments

Comments
 (0)