Skip to content

Commit 0a3df2e

Browse files
committed
Merge branch '3.8.x' into 4.0.x
* 3.8.x: Keep NVARCHAR(MAX) length as -1 (doctrine#6251)
2 parents 5d88359 + fb222c5 commit 0a3df2e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-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/SQLServerSchemaManagerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,19 @@ public function testPkOrdering(): void
129129

130130
self::assertSame(['colB', 'colA'], $firstIndex->getColumns());
131131
}
132+
133+
public function testNvarcharMaxIsLengthMinus1(): void
134+
{
135+
$sql = 'CREATE TABLE test_nvarchar_max (
136+
col_nvarchar_max NVARCHAR(MAX),
137+
col_nvarchar NVARCHAR(128)
138+
)';
139+
140+
$this->connection->executeStatement($sql);
141+
142+
$table = $this->schemaManager->introspectTable('test_nvarchar_max');
143+
144+
self::assertSame(-1, $table->getColumn('col_nvarchar_max')->getLength());
145+
self::assertSame(128, $table->getColumn('col_nvarchar')->getLength());
146+
}
132147
}

0 commit comments

Comments
 (0)