Skip to content

Commit

Permalink
Support for backslashes in default values
Browse files Browse the repository at this point in the history
It is now possible to use `\`, or other escaped characters, in default
values for a column.

Previously this lead to a confusion when diffing actual and expected
schema leading to perpetual out of sync schema.
  • Loading branch information
PowerKiKi committed Sep 9, 2017
1 parent 8d18a33 commit 4dfc5c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public function getListTableColumnsSQL($table, $database = null)
}

return "SELECT COLUMN_NAME AS Field, COLUMN_TYPE AS Type, IS_NULLABLE AS `Null`, ".
"COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment, " .
"COLUMN_KEY AS `Key`, TRIM('\'' FROM QUOTE(COLUMN_DEFAULT)) AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment, " .
"CHARACTER_SET_NAME AS CharacterSet, COLLATION_NAME AS Collation ".
"FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = " . $database . " AND TABLE_NAME = " . $table;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
$this->assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull());
}

public function testEscapedDefaultValueMustBePreserved()
{
$value = "a\\0a\\'a\"a\na\ra\ta\\Za\\\\a";

$table = new Table('string_escaped_default_value');
$table->addColumn('def_string', 'string', array('default' => $value));
$this->_sm->dropAndCreateTable($table);

$onlineTable = $this->_sm->listTableDetails('string_escaped_default_value');
$this->assertSame($value, $onlineTable->getColumn('def_string')->getDefault());

$comparator = new Comparator();
$this->assertFalse($comparator->diffTable($table, $onlineTable));
}

public function testColumnCollation()
{
$table = new Table('test_collation');
Expand Down

0 comments on commit 4dfc5c2

Please sign in to comment.