diff --git a/src/Platforms/SQLServerPlatform.php b/src/Platforms/SQLServerPlatform.php index a4e81c6e5e4..ac5cf8eba90 100644 --- a/src/Platforms/SQLServerPlatform.php +++ b/src/Platforms/SQLServerPlatform.php @@ -1306,7 +1306,7 @@ public function getAsciiStringTypeDeclarationSQL(array $column): string { $length = $column['length'] ?? null; - if (! isset($column['fixed'])) { + if (empty($column['fixed'])) { return sprintf('VARCHAR(%d)', $length ?? 255); } diff --git a/tests/Platforms/SQLServerPlatformTest.php b/tests/Platforms/SQLServerPlatformTest.php index 4cb48bc59ab..b9e5dadf1ec 100644 --- a/tests/Platforms/SQLServerPlatformTest.php +++ b/tests/Platforms/SQLServerPlatformTest.php @@ -123,10 +123,20 @@ public function testGeneratesTypeDeclarationsForStrings(): void 'NVARCHAR(50)', $this->platform->getStringTypeDeclarationSQL(['length' => 50]), ); + self::assertEquals( + 'NVARCHAR(50)', + $this->platform->getStringTypeDeclarationSQL( + ['length' => 50, 'fixed' => false], + ), + ); self::assertEquals( 'NVARCHAR(255)', $this->platform->getStringTypeDeclarationSQL([]), ); + self::assertEquals( + 'NVARCHAR(255)', + $this->platform->getStringTypeDeclarationSQL(['fixed' => false]), + ); self::assertSame('VARCHAR(MAX)', $this->platform->getClobTypeDeclarationSQL([])); self::assertSame( 'VARCHAR(MAX)', @@ -134,6 +144,34 @@ public function testGeneratesTypeDeclarationsForStrings(): void ); } + public function testGeneratesTypeDeclarationsForAsciiStrings(): void + { + self::assertEquals( + 'CHAR(10)', + $this->platform->getAsciiStringTypeDeclarationSQL( + ['length' => 10, 'fixed' => true], + ), + ); + self::assertEquals( + 'VARCHAR(50)', + $this->platform->getAsciiStringTypeDeclarationSQL(['length' => 50]), + ); + self::assertEquals( + 'VARCHAR(50)', + $this->platform->getAsciiStringTypeDeclarationSQL( + ['length' => 50, 'fixed' => false], + ), + ); + self::assertEquals( + 'VARCHAR(255)', + $this->platform->getAsciiStringTypeDeclarationSQL([]), + ); + self::assertEquals( + 'VARCHAR(255)', + $this->platform->getAsciiStringTypeDeclarationSQL(['fixed' => false]), + ); + } + public function testPrefersIdentityColumns(): void { self::assertTrue($this->platform->prefersIdentityColumns());