Skip to content

Commit 36e95c3

Browse files
authored
Fix ROWS_QUERY event parsing long queries (#117)
1 parent 7a94fef commit 36e95c3

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/MySQLReplication/Event/RowsQueryEvent.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class RowsQueryEvent extends EventCommon
1616
{
1717
public function makeRowsQueryDTO(): RowsQueryDTO
1818
{
19-
// $this->binaryDataReader->advance(1);
19+
$this->binaryDataReader->advance(1);
2020
return new RowsQueryDTO(
2121
$this->eventInfo,
22-
$this->binaryDataReader->read($this->binaryDataReader->readInt8()),
22+
$this->binaryDataReader->read($this->eventInfo->getSizeNoHeader() - 1),
2323
);
2424
}
2525
}

tests/Integration/RowsQueryTest.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44

55
namespace MySQLReplication\Tests\Integration;
66

7+
use Generator;
78
use MySQLReplication\Definitions\ConstEventType;
89
use MySQLReplication\Event\DTO\QueryDTO;
910
use MySQLReplication\Event\DTO\RowsQueryDTO;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1012

1113
final class RowsQueryTest extends BaseCase
1214
{
13-
public function testThatTheEditingQueryIsReadFromBinLog(): void
15+
#[DataProvider('provideQueries')]
16+
public function testThatTheEditingQueryIsReadFromBinLog(string $query): void
1417
{
1518
$this->connection->executeStatement(
1619
'CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))'
1720
);
1821

19-
$insertQuery = 'INSERT INTO test (data) VALUES(\'Hello\') /* Foo:Bar; */';
20-
$this->connection->executeStatement($insertQuery);
22+
$this->connection->executeStatement($query);
2123

2224
// The Create Table Query ... irrelevant content for this test
2325
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
@@ -26,7 +28,15 @@ public function testThatTheEditingQueryIsReadFromBinLog(): void
2628

2729
$rowsQueryEvent = $this->getEvent();
2830
self::assertInstanceOf(RowsQueryDTO::class, $rowsQueryEvent);
29-
self::assertSame($insertQuery, $rowsQueryEvent->query);
31+
self::assertSame($query, $rowsQueryEvent->query);
32+
}
33+
34+
public static function provideQueries(): Generator
35+
{
36+
yield 'Short Query' => ['INSERT INTO test (data) VALUES(\'Hello\') /* Foo:Bar; */'];
37+
38+
$comment = '/* Foo:Bar; Bar:Baz; Baz:Quo; Quo:Foo; Quo:Foo; Quo:Foo; Quo:Foo; Foo:Baz; */';
39+
yield 'Extra Long Query' => [$comment . ' INSERT INTO test (data) VALUES(\'Hello\') ' . $comment];
3040
}
3141

3242
protected function getIgnoredEvents(): array

0 commit comments

Comments
 (0)