Skip to content

Commit

Permalink
Fixed parsing MySQL create table flags (options without a value)
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Dec 7, 2018
1 parent 1b19356 commit 6e1bb80
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
30 changes: 16 additions & 14 deletions lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use function strpos;
use function strtok;
use function strtolower;
use function trim;

/**
* Schema manager for the MySql RDBMS.
Expand Down Expand Up @@ -305,25 +304,28 @@ public function listTableDetails($tableName)
$table->addOption('autoincrement', $tableOptions['AUTO_INCREMENT']);
}
$table->addOption('comment', $tableOptions['TABLE_COMMENT']);
$table->addOption('create_options', $this->parseCreateOptions($tableOptions['CREATE_OPTIONS']));

if ($tableOptions['CREATE_OPTIONS'] === null) {
return $table;
}
return $table;
}

$createOptionsString = trim($tableOptions['CREATE_OPTIONS']);
/**
* @return string[]|true[]
*/
private function parseCreateOptions(string $string) : array
{
$options = [];

$createOptions = [];
if ($string === '') {
return $options;
}

if ($createOptionsString !== '') {
foreach (explode(' ', $createOptionsString) as $option) {
[$createOption, $value] = explode('=', $option);
foreach (explode(' ', $string) as $pair) {
$parts = explode('=', $pair, 2);

$createOptions[$createOption] = $value;
}
$options[$parts[0]] = $parts[1] ?? true;
}

$table->addOption('create_options', $createOptions);

return $table;
return $options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public function testEnsureTableOptionsAreReflectedInMetadata() : void
ROW_FORMAT COMPRESSED
COMMENT 'This is a test'
AUTO_INCREMENT=42
PARTITION BY HASH (col1)
SQL;

$this->connection->query($sql);
Expand All @@ -511,7 +512,10 @@ public function testEnsureTableOptionsAreReflectedInMetadata() : void
self::assertEquals('utf8_general_ci', $onlineTable->getOption('collation'));
self::assertEquals(42, $onlineTable->getOption('autoincrement'));
self::assertEquals('This is a test', $onlineTable->getOption('comment'));
self::assertEquals(['row_format' => 'COMPRESSED'], $onlineTable->getOption('create_options'));
self::assertEquals([
'row_format' => 'COMPRESSED',
'partitioned' => true,
], $onlineTable->getOption('create_options'));
}

public function testEnsureTableWithoutOptionsAreReflectedInMetadata() : void
Expand Down

0 comments on commit 6e1bb80

Please sign in to comment.