Skip to content

Commit 0cc102b

Browse files
committed
fix: SQLSRV Forge::modifyColumn() changes NULL incorrectly
1 parent 96821c2 commit 0cc102b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

system/Database/SQLSRV/Forge.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,14 @@ protected function _alterTable(string $alterType, string $table, $field)
203203
. " DEFAULT {$data['default']} FOR " . $this->db->escapeIdentifiers($data['name']);
204204
}
205205

206+
$nullable = true; // Nullable by default.
206207
if (isset($data['null'])) {
207-
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escapeIdentifiers($data['name'])
208-
. ($data['null'] === true ? ' DROP' : '') . " {$data['type']}{$data['length']} NOT NULL";
208+
if ($data['null'] === false || $data['null'] === ' NOT ' . $this->null) {
209+
$nullable = false;
210+
}
209211
}
212+
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escapeIdentifiers($data['name'])
213+
. " {$data['type']}{$data['length']} " . ($nullable === true ? '' : 'NOT') . ' NULL';
210214

211215
if (! empty($data['comment'])) {
212216
$sqls[] = 'EXEC sys.sp_addextendedproperty '

tests/system/Database/Live/ForgeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,9 +1313,9 @@ public function testModifyColumnNullTrue()
13131313

13141314
public function testModifyColumnNullFalse()
13151315
{
1316-
if ($this->db->DBDriver === 'SQLSRV') {
1317-
$this->markTestSkipped('SQLSRV does not support getFieldData() nullable.');
1318-
}
1316+
// if ($this->db->DBDriver === 'SQLSRV') {
1317+
// $this->markTestSkipped('SQLSRV does not support getFieldData() nullable.');
1318+
// }
13191319

13201320
$this->forge->dropTable('forge_test_modify', true);
13211321

@@ -1341,7 +1341,7 @@ public function testModifyColumnNullFalse()
13411341
$col3 = $this->getMetaData('col3', 'forge_test_modify');
13421342
$this->assertFalse($col3->nullable);
13431343

1344-
$this->forge->dropTable('forge_test_modify', true);
1344+
// $this->forge->dropTable('forge_test_modify', true);
13451345
}
13461346

13471347
private function getMetaData(string $column, string $table): stdClass

0 commit comments

Comments
 (0)