Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ROWS_QUERY event parsing long queries #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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
Loading