Skip to content
Merged
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
6 changes: 5 additions & 1 deletion src/MySQLReplication/Event/RowEvent/RowEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,11 @@ protected function getDatetime2(ColumnDTO $columnDTO): ?string
$year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second
);
if ($formattedDate) {
return $formattedDate . $fsp;
if ($fsp > 0) {
return vsprintf('%s.%06u', [$formattedDate, $fsp]);
} else {
return $formattedDate;
}
}

return null;
Expand Down
40 changes: 40 additions & 0 deletions tests/Integration/TypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,46 @@ public function testShouldReturnNullOnZeroDateDateTime(): void
self::assertNull($event->values[0]['test']);
}

public function testShouldBeDateTime2(): void
{
$create_query = 'CREATE TABLE test (test DATETIME(6));';
$insert_query = 'INSERT INTO test VALUES("1984-12-03 12:33:07.023450")';

$event = $this->createAndInsertValue($create_query, $insert_query);

self::assertEquals('1984-12-03 12:33:07.023450', $event->values[0]['test']);
}

public function testShouldBeZeroDateTime2(): void
{
$create_query = 'CREATE TABLE test (id INTEGER, test DATETIME(6) NOT NULL DEFAULT 0);';
$insert_query = 'INSERT INTO test (id) VALUES(1)';

$event = $this->createAndInsertValue($create_query, $insert_query);

self::assertNull($event->values[0]['test']);
}

public function testShouldBeBrokenDateTime2(): void
{
$create_query = 'CREATE TABLE test (test DATETIME(6) NOT NULL);';
$insert_query = 'INSERT INTO test VALUES("2013-00-00 00:00:00")';

$event = $this->createAndInsertValue($create_query, $insert_query);

self::assertNull($event->values[0]['test']);
}

public function testShouldReturnNullOnZeroDateDateTime2(): void
{
$create_query = 'CREATE TABLE test (test DATETIME(6) NOT NULL);';
$insert_query = 'INSERT INTO test VALUES("0000-00-00 00:00:00")';

$event = $this->createAndInsertValue($create_query, $insert_query);

self::assertNull($event->values[0]['test']);
}

public function testShouldBeYear(): void
{
$create_query = 'CREATE TABLE test (test YEAR(4), test2 YEAR, test3 YEAR)';
Expand Down