From 590e8bdb78e71e0248aa435060404313fd0bd112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 14 Nov 2021 13:57:41 +0100 Subject: [PATCH] Fix MSSQL CLOB column type to support Unicode --- .../DBAL/Platforms/SQLServer2005Platform.php | 2 +- .../DBAL/Platforms/SQLServerPlatform.php | 2 +- .../AbstractSQLServerPlatformTestCase.php | 20 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/SQLServer2005Platform.php b/lib/Doctrine/DBAL/Platforms/SQLServer2005Platform.php index 6f02bb8ff51..4d83ec74f2a 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServer2005Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServer2005Platform.php @@ -33,7 +33,7 @@ public function supportsLimitOffset() */ public function getClobTypeDeclarationSQL(array $column) { - return 'VARCHAR(MAX)'; + return 'NVARCHAR(MAX)'; } /** diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 2b958018603..33edd81d152 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1238,7 +1238,7 @@ public function getBinaryMaxLength() */ public function getClobTypeDeclarationSQL(array $column) { - return 'VARCHAR(MAX)'; + return 'NVARCHAR(MAX)'; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 26e75423ab4..65d331f3f48 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -143,9 +143,9 @@ public function testGeneratesTypeDeclarationsForStrings(): void 'NVARCHAR(255)', $this->platform->getVarcharTypeDeclarationSQL([]) ); - self::assertSame('VARCHAR(MAX)', $this->platform->getClobTypeDeclarationSQL([])); + self::assertSame('NVARCHAR(MAX)', $this->platform->getClobTypeDeclarationSQL([])); self::assertSame( - 'VARCHAR(MAX)', + 'NVARCHAR(MAX)', $this->platform->getClobTypeDeclarationSQL(['length' => 5, 'fixed' => true]) ); } @@ -741,7 +741,7 @@ public function getAlterTableColumnCommentsSQL(): array public function getCreateTableColumnTypeCommentsSQL(): array { return [ - 'CREATE TABLE test (id INT NOT NULL, data VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))', + 'CREATE TABLE test (id INT NOT NULL, data NVARCHAR(MAX) NOT NULL, PRIMARY KEY (id))', "EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:array)', " . "N'SCHEMA', 'dbo', N'TABLE', 'test', N'COLUMN', data", ]; @@ -780,8 +780,8 @@ public function testGeneratesCreateTableSQLWithColumnComments(): void . 'comment INT NOT NULL, ' . '[comment_quoted] INT NOT NULL, ' . '[create] INT NOT NULL, ' - . 'commented_type VARCHAR(MAX) NOT NULL, ' - . 'commented_type_with_comment VARCHAR(MAX) NOT NULL, ' + . 'commented_type NVARCHAR(MAX) NOT NULL, ' + . 'commented_type_with_comment NVARCHAR(MAX) NOT NULL, ' . 'comment_with_string_literal_char NVARCHAR(255) NOT NULL, ' . 'PRIMARY KEY (id))', "EXEC sp_addextendedproperty N'MS_Description', " @@ -988,14 +988,14 @@ public function testGeneratesAlterTableSQLWithColumnComments(): void 'ALTER TABLE mytable ADD added_comment INT NOT NULL', 'ALTER TABLE mytable ADD [added_comment_quoted] INT NOT NULL', 'ALTER TABLE mytable ADD [select] INT NOT NULL', - 'ALTER TABLE mytable ADD added_commented_type VARCHAR(MAX) NOT NULL', - 'ALTER TABLE mytable ADD added_commented_type_with_comment VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ADD added_commented_type NVARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ADD added_commented_type_with_comment NVARCHAR(MAX) NOT NULL', 'ALTER TABLE mytable ADD added_comment_with_string_literal_char NVARCHAR(255) NOT NULL', 'ALTER TABLE mytable DROP COLUMN comment_integer_0', 'ALTER TABLE mytable ALTER COLUMN comment_null NVARCHAR(255) NOT NULL', - 'ALTER TABLE mytable ALTER COLUMN comment_empty_string VARCHAR(MAX) NOT NULL', - 'ALTER TABLE mytable ALTER COLUMN [comment_quoted] VARCHAR(MAX) NOT NULL', - 'ALTER TABLE mytable ALTER COLUMN [create] VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN comment_empty_string NVARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN [comment_quoted] NVARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN [create] NVARCHAR(MAX) NOT NULL', 'ALTER TABLE mytable ALTER COLUMN commented_type INT NOT NULL', // Added columns.