-
Notifications
You must be signed in to change notification settings - Fork 102
Implement rows query event #112
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MySQLReplication\Event\DTO; | ||
|
||
use MySQLReplication\Definitions\ConstEventsNames; | ||
use MySQLReplication\Event\EventInfo; | ||
|
||
class RowsQueryDTO extends EventDTO | ||
{ | ||
private ConstEventsNames $type = ConstEventsNames::ROWS_QUERY; | ||
|
||
public function __construct( | ||
EventInfo $eventInfo, | ||
public readonly string $query, | ||
) { | ||
parent::__construct($eventInfo); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return PHP_EOL . | ||
'=== Event ' . $this->getType() . ' === ' . PHP_EOL . | ||
'Date: ' . $this->eventInfo->getDateTime() . PHP_EOL . | ||
'Log position: ' . $this->eventInfo->pos . PHP_EOL . | ||
'Event size: ' . $this->eventInfo->size . PHP_EOL . | ||
'Query: ' . $this->query . PHP_EOL; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type->value; | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return get_object_vars($this); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MySQLReplication\Event; | ||
|
||
use MySQLReplication\Event\DTO\RowsQueryDTO; | ||
|
||
/** | ||
* The Rows_query event is within the binary log when the MySQL Option `binlog_rows_query_log_events` | ||
* is enabled. | ||
* | ||
* @see https://dev.mysql.com/doc/dev/mysql-server/latest/classRows__query__log__event.html | ||
*/ | ||
class RowsQueryEvent extends EventCommon | ||
{ | ||
public function makeRowsQueryDTO(): RowsQueryDTO | ||
{ | ||
// $this->binaryDataReader->advance(1); | ||
return new RowsQueryDTO( | ||
$this->eventInfo, | ||
$this->binaryDataReader->read($this->binaryDataReader->readInt8()), | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MySQLReplication\Tests\Integration; | ||
|
||
use MySQLReplication\Definitions\ConstEventType; | ||
use MySQLReplication\Event\DTO\QueryDTO; | ||
use MySQLReplication\Event\DTO\RowsQueryDTO; | ||
|
||
final class RowsQueryTest extends BaseCase | ||
{ | ||
public function testThatTheEditingQueryIsReadFromBinLog(): 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); | ||
|
||
// The Create Table Query ... irrelevant content for this test | ||
self::assertInstanceOf(QueryDTO::class, $this->getEvent()); | ||
// The BEGIN Query ... irrelevant content for this test | ||
self::assertInstanceOf(QueryDTO::class, $this->getEvent()); | ||
|
||
$rowsQueryEvent = $this->getEvent(); | ||
self::assertInstanceOf(RowsQueryDTO::class, $rowsQueryEvent); | ||
self::assertSame($insertQuery, $rowsQueryEvent->query); | ||
} | ||
|
||
protected function getIgnoredEvents(): array | ||
{ | ||
return [ConstEventType::GTID_LOG_EVENT->value]; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.