Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/MySQLReplication/BinaryDataReader/BinaryDataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,28 +229,27 @@ public function readIntBeBySize(int $size): int

public function readInt8(): int
{
return unpack('c', $this->read(self::UNSIGNED_CHAR_LENGTH))[1];
$re = unpack('c', $this->read(self::UNSIGNED_CHAR_LENGTH))[1];
return $re >= 0x80 ? $re - 0x100 : $re;
}

public function readInt16Be(): int
{
return unpack('n', $this->read(self::UNSIGNED_SHORT_LENGTH))[1];
$re = unpack('n', $this->read(self::UNSIGNED_SHORT_LENGTH))[1];
return $re >= 0x8000 ? $re - 0x10000 : $re;
}

public function readInt24Be(): int
{
$data = unpack('C3', $this->read(self::UNSIGNED_INT24_LENGTH));
$res = ($data[1] << 16) | ($data[2] << 8) | $data[3];
if ($res >= 0x800000) {
$res -= 0x1000000;
}

return $res;
$re = ($data[1] << 16) | ($data[2] << 8) | $data[3];
return $re >= 0x800000 ? $re - 0x1000000 : $re;
}

public function readInt32Be(): int
{
return unpack('i', strrev($this->read(self::UNSIGNED_INT32_LENGTH)))[1];
$re = unpack('N', $this->read(self::UNSIGNED_INT32_LENGTH))[1];
return $re >= 0x80000000 ? $re - 0x100000000 : $re;
}

public function readInt40Be(): int
Expand Down
6 changes: 4 additions & 2 deletions tests/Integration/TypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ public function shouldBeDecimalLongValues2(): void
*/
public function shouldBeDecimalNegativeValues(): void
{
$create_query = 'CREATE TABLE test (test DECIMAL(20,10))';
$insert_query = 'INSERT INTO test VALUES(-42000.123456)';
$create_query = 'CREATE TABLE test (test DECIMAL(20,10), test2 DECIMAL(11,4), test3 DECIMAL(40,30))';
$insert_query = 'INSERT INTO test VALUES(-42000.123456, -51.1234, -51.123456789098765432123456789)';

$event = $this->createAndInsertValue($create_query, $insert_query);

self::assertEquals('-42000.1234560000', $event->getValues()[0]['test']);
self::assertEquals('-51.1234', $event->getValues()[0]['test2']);
self::assertEquals('-51.123456789098765432123456789000', $event->getValues()[0]['test3']);
}

/**
Expand Down