-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement rows query event from mysql
- Loading branch information
Showing
9 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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]; | ||
} | ||
} |