From 04ebb8e77ed86da378e31b29fd6d7fff9cf54811 Mon Sep 17 00:00:00 2001 From: Quentin Date: Mon, 6 May 2024 22:56:44 +0200 Subject: [PATCH] Fix condition on Ascii String for SQL Server fixed is always set (to either true or false). --- src/Platforms/SQLServerPlatform.php | 2 +- tests/Platforms/SQLServerPlatformTest.php | 38 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) 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());