Skip to content

SQLServer - fix unicode support for text type - nvarchar(max) instead of varchar(max) #6421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ public function getAsciiStringTypeDeclarationSQL(array $column): string
*/
public function getClobTypeDeclarationSQL(array $column): string
{
return 'VARCHAR(MAX)';
return 'NVARCHAR(MAX)';
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Schema/SQLServerSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
break;

case 'nvarchar':
// TEXT type is returned as NVARCHAR(MAX) with a length of -1
if ($length === -1) {
$dbType = 'text';
break;
}

Expand All @@ -98,7 +100,9 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
break;

case 'varchar':
// TEXT type is returned as VARCHAR(MAX) with a length of -1
// keep for backward compatibility
// as some fields might come back as VARCHAR(MAX) with a length of -1
// and we want them to be mapped to the 'text' type
if ($length === -1) {
$dbType = 'text';
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Platforms/SQLServerPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public function testGeneratesTypeDeclarationForIntegers(): void

public function testGeneratesTypeDeclarationsForStrings(): void
{
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]),
);
}
Expand Down