From 4dfc5c25a1fdee4002c74e34f4a9b8521a761e98 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 10 Sep 2017 00:14:25 +0900 Subject: [PATCH] Support for backslashes in default values 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. --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 2 +- .../Functional/Schema/MySqlSchemaManagerTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 5d2b6339dac..d022ec217af 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -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; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 9383848500b..ae4c69c8d22 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -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');