From 7d77490496287c57c7e5bc7512138c65c9b1cecf Mon Sep 17 00:00:00 2001 From: Denis Zunke Date: Mon, 6 May 2024 14:32:53 +0200 Subject: [PATCH] Fix ROWS_QUERY event parsing long queries --- src/MySQLReplication/Event/RowsQueryEvent.php | 4 ++-- tests/Integration/RowsQueryTest.php | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/MySQLReplication/Event/RowsQueryEvent.php b/src/MySQLReplication/Event/RowsQueryEvent.php index 3ddc611..4e3fbd9 100644 --- a/src/MySQLReplication/Event/RowsQueryEvent.php +++ b/src/MySQLReplication/Event/RowsQueryEvent.php @@ -16,10 +16,10 @@ class RowsQueryEvent extends EventCommon { public function makeRowsQueryDTO(): RowsQueryDTO { - // $this->binaryDataReader->advance(1); + $this->binaryDataReader->advance(1); return new RowsQueryDTO( $this->eventInfo, - $this->binaryDataReader->read($this->binaryDataReader->readInt8()), + $this->binaryDataReader->read($this->eventInfo->getSizeNoHeader() - 1), ); } } diff --git a/tests/Integration/RowsQueryTest.php b/tests/Integration/RowsQueryTest.php index 129a35f..16887ae 100644 --- a/tests/Integration/RowsQueryTest.php +++ b/tests/Integration/RowsQueryTest.php @@ -4,20 +4,22 @@ namespace MySQLReplication\Tests\Integration; +use Generator; use MySQLReplication\Definitions\ConstEventType; use MySQLReplication\Event\DTO\QueryDTO; use MySQLReplication\Event\DTO\RowsQueryDTO; +use PHPUnit\Framework\Attributes\DataProvider; final class RowsQueryTest extends BaseCase { - public function testThatTheEditingQueryIsReadFromBinLog(): void + #[DataProvider('provideQueries')] + public function testThatTheEditingQueryIsReadFromBinLog(string $query): void { $this->connection->executeStatement( 'CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))' ); - $insertQuery = 'INSERT INTO test (data) VALUES(\'Hello\') /* Foo:Bar; */'; - $this->connection->executeStatement($insertQuery); + $this->connection->executeStatement($query); // The Create Table Query ... irrelevant content for this test self::assertInstanceOf(QueryDTO::class, $this->getEvent()); @@ -26,7 +28,15 @@ public function testThatTheEditingQueryIsReadFromBinLog(): void $rowsQueryEvent = $this->getEvent(); self::assertInstanceOf(RowsQueryDTO::class, $rowsQueryEvent); - self::assertSame($insertQuery, $rowsQueryEvent->query); + self::assertSame($query, $rowsQueryEvent->query); + } + + public static function provideQueries(): Generator + { + yield 'Short Query' => ['INSERT INTO test (data) VALUES(\'Hello\') /* Foo:Bar; */']; + + $comment = '/* Foo:Bar; Bar:Baz; Baz:Quo; Quo:Foo; Quo:Foo; Quo:Foo; Quo:Foo; Foo:Baz; */'; + yield 'Extra Long Query' => [$comment . ' INSERT INTO test (data) VALUES(\'Hello\') ' . $comment]; } protected function getIgnoredEvents(): array