From 37152804fb58529c8236fb5d9d153a97e65fe217 Mon Sep 17 00:00:00 2001 From: michalsn Date: Tue, 29 Oct 2024 22:45:29 +0100 Subject: [PATCH] set collation for sqlsrv --- .github/workflows/reusable-phpunit-test.yml | 2 +- system/Database/SQLSRV/Forge.php | 8 ++++---- .../Migrations/20160428212500_Create_test_tables.php | 1 + tests/system/Database/Live/ForgeTest.php | 12 +++++++++--- tests/system/Database/Live/GetTest.php | 2 +- tests/system/Database/Live/LikeTest.php | 6 ------ 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/reusable-phpunit-test.yml b/.github/workflows/reusable-phpunit-test.yml index 84ade1d08862..9758d6eb5410 100644 --- a/.github/workflows/reusable-phpunit-test.yml +++ b/.github/workflows/reusable-phpunit-test.yml @@ -138,7 +138,7 @@ jobs: steps: - name: Create database for MSSQL Server if: ${{ inputs.db-platform == 'SQLSRV' }} - run: sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test" + run: sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test COLLATE Latin1_General_100_CS_AS_SC_UTF8" - name: Install latest ImageMagick if: ${{ contains(inputs.extra-extensions, 'imagick') }} diff --git a/system/Database/SQLSRV/Forge.php b/system/Database/SQLSRV/Forge.php index 3bfda3bfe895..d121560c9d47 100644 --- a/system/Database/SQLSRV/Forge.php +++ b/system/Database/SQLSRV/Forge.php @@ -212,10 +212,10 @@ protected function _alterTable(string $alterType, string $table, $processedField $sql = <<db->DBDriver === 'SQLSRV') { unset($dataTypeFields['type_timestamp']); + $dataTypeFields['type_text'] = ['type' => 'NVARCHAR(max)', 'null' => true]; } if ($this->db->DBDriver === 'Postgre' || $this->db->DBDriver === 'SQLSRV') { diff --git a/tests/system/Database/Live/ForgeTest.php b/tests/system/Database/Live/ForgeTest.php index 7fccd6b1d298..64d8dbd7e576 100644 --- a/tests/system/Database/Live/ForgeTest.php +++ b/tests/system/Database/Live/ForgeTest.php @@ -1615,9 +1615,15 @@ public function testDropKey(): void public function testAddTextColumnWithConstraint(): void { // some DBMS do not allow a constraint for type TEXT - $this->forge->addColumn('user', [ - 'text_with_constraint' => ['type' => 'text', 'constraint' => 255, 'default' => ''], - ]); + if ($this->db->DBDriver === 'SQLSRV') { + $this->forge->addColumn('user', [ + 'text_with_constraint' => ['type' => 'nvarchar(max)', 'default' => ''], + ]); + } else { + $this->forge->addColumn('user', [ + 'text_with_constraint' => ['type' => 'text', 'constraint' => 255, 'default' => ''], + ]); + } $this->assertTrue($this->db->fieldExists('text_with_constraint', 'user')); diff --git a/tests/system/Database/Live/GetTest.php b/tests/system/Database/Live/GetTest.php index 681af7344183..ce98ebf413e0 100644 --- a/tests/system/Database/Live/GetTest.php +++ b/tests/system/Database/Live/GetTest.php @@ -178,7 +178,7 @@ public function testGetFieldData(): void $this->assertSame('int', $typeTest[0]->type_name); // INTEGER AUTOINC $this->assertSame('varchar', $typeTest[1]->type_name); // VARCHAR $this->assertSame('char', $typeTest[2]->type_name); // CHAR - $this->assertSame('text', $typeTest[3]->type_name); // TEXT + $this->assertSame('nvarchar', $typeTest[3]->type_name); // TEXT $this->assertSame('smallint', $typeTest[4]->type_name); // SMALLINT $this->assertSame('int', $typeTest[5]->type_name); // INTEGER $this->assertSame('float', $typeTest[6]->type_name); // FLOAT diff --git a/tests/system/Database/Live/LikeTest.php b/tests/system/Database/Live/LikeTest.php index 51ad0c19f228..9591eef72ea8 100644 --- a/tests/system/Database/Live/LikeTest.php +++ b/tests/system/Database/Live/LikeTest.php @@ -79,12 +79,6 @@ public function testLikeCaseInsensitive(): void #[DataProvider('provideMultibyteCharacters')] public function testLikeCaseInsensitiveWithMultibyteCharacter(string $match, string $result): void { - if ($this->db->DBDriver === 'SQLSRV') { - $this->markTestSkipped( - 'Currently Builder class does not fully support Unicode strings in SQLSRV.' - ); - } - $wai = $this->db->table('without_auto_increment')->like('value', $match, 'both', null, true)->get(); $wai = $wai->getRow();