Skip to content

Commit 9bc1926

Browse files
committed
fix - handle not existsing value in enum definitions
1 parent 62493a2 commit 9bc1926

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/MySQLReplication/Event/RowEvent/RowEvent.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,14 @@ private function getColumnData($colsBitmap)
369369
}
370370
elseif ($column['type'] == ConstFieldType::ENUM)
371371
{
372-
$values[$name] = $column['enum_values'][$this->binaryDataReader->readUIntBySize($column['size']) - 1];
372+
$value = $this->binaryDataReader->readUIntBySize($column['size']) - 1;
373+
374+
$values[$name] = '';
375+
// check if given value exists in enums, if there not existing enum mysql sets to empty string.
376+
if (array_key_exists($value, $column['enum_values']))
377+
{
378+
$values[$name] = $column['enum_values'][$value];
379+
}
373380
}
374381
elseif ($column['type'] == ConstFieldType::SET)
375382
{

tests/Integration/TypesTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,20 @@ public function shouldBeBit()
577577
*/
578578
public function shouldBeEnum()
579579
{
580-
$create_query = "CREATE TABLE test (test ENUM('a', 'ba', 'c'), test2 ENUM('a', 'ba', 'c')) CHARACTER SET latin1 COLLATE latin1_bin;";
581-
$insert_query = "INSERT INTO test VALUES('ba', 'a')";
580+
$create_query = "CREATE TABLE test
581+
(
582+
test ENUM('a', 'ba', 'c'),
583+
test2 ENUM('a', 'ba', 'c'),
584+
test3 ENUM('foo', 'bar')
585+
)
586+
CHARACTER SET latin1 COLLATE latin1_bin;";
587+
$insert_query = "INSERT INTO test VALUES('ba', 'a', 'not_exists')";
582588

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

585591
$this->assertEquals('ba', $event->getValues()[0]['test']);
586592
$this->assertEquals('a', $event->getValues()[0]['test2']);
593+
$this->assertEquals('', $event->getValues()[0]['test3']);
587594
}
588595

589596
/**

0 commit comments

Comments
 (0)