Skip to content

Commit

Permalink
set collation for sqlsrv
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Oct 29, 2024
1 parent 605c376 commit 3e3e722
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reusable-phpunit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand Down
8 changes: 4 additions & 4 deletions system/Database/SQLSRV/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ protected function _alterTable(string $alterType, string $table, $processedField

$sql = <<<SQL
SELECT name
FROM SYS.DEFAULT_CONSTRAINTS
WHERE PARENT_OBJECT_ID = OBJECT_ID('{$fullTable}')
AND PARENT_COLUMN_ID IN (
SELECT column_id FROM sys.columns WHERE NAME IN ({$fields}) AND object_id = OBJECT_ID(N'{$fullTable}')
FROM sys.default_constraints
WHERE parent_object_id = OBJECT_ID('{$fullTable}')
AND parent_column_id IN (
SELECT column_id FROM sys.columns WHERE name IN ({$fields}) AND object_id = OBJECT_ID(N'{$fullTable}')
)
SQL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function up(): void

if ($this->db->DBDriver === 'SQLSRV') {
unset($dataTypeFields['type_timestamp']);
$dataTypeFields['type_text'] = ['type' => 'NVARCHAR(max)', 'null' => true];
}

if ($this->db->DBDriver === 'Postgre' || $this->db->DBDriver === 'SQLSRV') {
Expand Down
12 changes: 9 additions & 3 deletions tests/system/Database/Live/ForgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
2 changes: 1 addition & 1 deletion tests/system/Database/Live/GetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions tests/system/Database/Live/LikeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 3e3e722

Please sign in to comment.