Skip to content

Commit

Permalink
Fix ROWS_QUERY event parsing long queries
Browse files Browse the repository at this point in the history
  • Loading branch information
DZunke committed May 6, 2024
1 parent 6150f0e commit 7d77490
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/MySQLReplication/Event/RowsQueryEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
}
18 changes: 14 additions & 4 deletions tests/Integration/RowsQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand Down

0 comments on commit 7d77490

Please sign in to comment.