Skip to content

Commit

Permalink
Feature/next release (#43)
Browse files Browse the repository at this point in the history
* added checking for eof (#42)
* adds support for column type 11 - TIME (mysql 5.5 only) (#41)
  • Loading branch information
krowinski authored Jun 22, 2018
1 parent 45c32f3 commit e178de2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/MySQLReplication/Definitions/ConstFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,4 +44,4 @@ class ConstFieldType
const INTERVAL = self::ENUM;

const IGNORE = 666;
}
}
7 changes: 5 additions & 2 deletions src/MySQLReplication/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class Event
{
const MARIADB_DUMMY_QUERY = '# Dum';
const EOF_HEADER_VALUE = 254;

/**
* @var BinLogSocketConnect
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 16 additions & 4 deletions src/MySQLReplication/Event/RowEvent/RowEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -403,7 +402,6 @@ public function makeTableMapDTO()
* @return WriteRowsDTO|null
* @throws InvalidArgumentException
* @throws BinaryDataReaderException
* @throws EventException
* @throws JsonBinaryDecoderException
* @throws MySQLReplicationException
*/
Expand Down Expand Up @@ -458,7 +456,6 @@ protected function rowInit()
/**
* @return array
* @throws BinaryDataReaderException
* @throws EventException
* @throws JsonBinaryDecoderException
* @throws MySQLReplicationException
*/
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -917,7 +916,6 @@ protected function getBit(array $column)
* @return DeleteRowsDTO
* @throws InvalidArgumentException
* @throws BinaryDataReaderException
* @throws EventException
* @throws JsonBinaryDecoderException
* @throws MySQLReplicationException
*/
Expand Down Expand Up @@ -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);
}
}

0 comments on commit e178de2

Please sign in to comment.