diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index e3ce138fe0f..a4423d6cfce 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -46,6 +46,8 @@ use function in_array; use function is_array; use function is_bool; +use function is_float; +use function is_int; use function is_string; use function preg_quote; use function preg_replace; @@ -2011,6 +2013,10 @@ public function getDefaultValueDeclarationSQL(array $field) : string return " DEFAULT '" . $this->convertBooleans($default) . "'"; } + if (is_int($default) || is_float($default)) { + return ' DEFAULT ' . $default; + } + return ' DEFAULT ' . $this->quoteStringLiteral($default); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index f2219ff918c..cbfe175702c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1063,12 +1063,9 @@ public function testColumnDefaultLifecycle() : void $table = new Table('col_def_lifecycle'); $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('column1', 'string', ['default' => null]); - $table->addColumn('column2', 'string', ['default' => false]); - $table->addColumn('column3', 'string', ['default' => true]); - $table->addColumn('column4', 'string', ['default' => 0]); - $table->addColumn('column5', 'string', ['default' => '']); - $table->addColumn('column6', 'string', ['default' => 'def']); - $table->addColumn('column7', 'integer', ['default' => 0]); + $table->addColumn('column2', 'string', ['default' => '']); + $table->addColumn('column3', 'string', ['default' => 'default1']); + $table->addColumn('column4', 'integer', ['default' => 0]); $table->setPrimaryKey(['id']); $this->schemaManager->dropAndCreateTable($table); @@ -1078,21 +1075,15 @@ public function testColumnDefaultLifecycle() : void self::assertNull($columns['id']->getDefault()); self::assertNull($columns['column1']->getDefault()); self::assertSame('', $columns['column2']->getDefault()); - self::assertSame('1', $columns['column3']->getDefault()); + self::assertSame('default1', $columns['column3']->getDefault()); self::assertSame('0', $columns['column4']->getDefault()); - self::assertSame('', $columns['column5']->getDefault()); - self::assertSame('def', $columns['column6']->getDefault()); - self::assertSame('0', $columns['column7']->getDefault()); $diffTable = clone $table; - $diffTable->changeColumn('column1', ['default' => false]); + $diffTable->changeColumn('column1', ['default' => '']); $diffTable->changeColumn('column2', ['default' => null]); - $diffTable->changeColumn('column3', ['default' => false]); + $diffTable->changeColumn('column3', ['default' => 'default2']); $diffTable->changeColumn('column4', ['default' => null]); - $diffTable->changeColumn('column5', ['default' => false]); - $diffTable->changeColumn('column6', ['default' => 666]); - $diffTable->changeColumn('column7', ['default' => null]); $comparator = new Comparator(); @@ -1102,11 +1093,8 @@ public function testColumnDefaultLifecycle() : void self::assertSame('', $columns['column1']->getDefault()); self::assertNull($columns['column2']->getDefault()); - self::assertSame('', $columns['column3']->getDefault()); + self::assertSame('default2', $columns['column3']->getDefault()); self::assertNull($columns['column4']->getDefault()); - self::assertSame('', $columns['column5']->getDefault()); - self::assertSame('666', $columns['column6']->getDefault()); - self::assertNull($columns['column7']->getDefault()); } public function testListTableWithBinary() : void diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 0b8e554300d..fb90d8105f2 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -1032,9 +1032,9 @@ public function testChangeColumnsTypeWithDefaultValue() : void $tableDiff->changedColumns['col_string'] = new ColumnDiff( 'col_string', - new Column('col_string', Type::getType('string'), ['default' => 666, 'fixed' => true]), + new Column('col_string', Type::getType('string'), ['default' => 'bar', 'fixed' => true]), ['fixed'], - new Column('col_string', Type::getType('string'), ['default' => 666]) + new Column('col_string', Type::getType('string'), ['default' => 'foo']) ); $expected = $this->platform->getAlterTableSQL($tableDiff); @@ -1047,7 +1047,7 @@ public function testChangeColumnsTypeWithDefaultValue() : void 'ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_FA2CB292 DEFAULT 666 FOR col_int', 'ALTER TABLE column_def_change_type DROP CONSTRAINT DF_829302E0_2725A6D0', 'ALTER TABLE column_def_change_type ALTER COLUMN col_string NCHAR(255) NOT NULL', - "ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_2725A6D0 DEFAULT '666' FOR col_string", + "ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_2725A6D0 DEFAULT 'bar' FOR col_string", ] ); }