Skip to content

Commit 62b57ae

Browse files
committed
Keep NVARCHAR(MAX) length as -1
1 parent 8bc0d9a commit 62b57ae

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Schema/SQLServerSchemaManager.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,20 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
8383

8484
switch ($dbType) {
8585
case 'nchar':
86-
case 'nvarchar':
8786
case 'ntext':
8887
// Unicode data requires 2 bytes per character
8988
$length /= 2;
9089
break;
9190

91+
case 'nvarchar':
92+
if ($length === -1) {
93+
break;
94+
}
95+
96+
// Unicode data requires 2 bytes per character
97+
$length /= 2;
98+
break;
99+
92100
case 'varchar':
93101
// TEXT type is returned as VARCHAR(MAX) with a length of -1
94102
if ($length === -1) {

tests/Functional/Schema/SchemaManagerFunctionalTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,19 @@ protected function findTableByName(array $tables, string $name): ?Table
14091409

14101410
return null;
14111411
}
1412+
1413+
public function testNvarcharMaxIsLengthMinus1(): void
1414+
{
1415+
$createTableSQL = 'CREATE TABLE test_nvarchar_max (
1416+
col_nvarchar_max NVARCHAR(MAX),
1417+
col_nvarchar NVARCHAR(128)
1418+
)';
1419+
$this->connection->executeStatement($createTableSQL);
1420+
1421+
$table = $this->schemaManager->introspectTable('test_nvarchar_max');
1422+
self::assertSame(-1, $table->getColumn('col_nvarchar_max')->getLength());
1423+
self::assertSame(128, $table->getColumn('col_nvarchar')->getLength());
1424+
}
14121425
}
14131426

14141427
interface ListTableColumnsDispatchEventListener

0 commit comments

Comments
 (0)