Skip to content

Commit 42f94ee

Browse files
committed
feat: SQLSRV getFieldData() supports nullable
1 parent 6988e74 commit 42f94ee

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

system/Database/SQLSRV/Connection.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,11 @@ protected function _enableForeignKeyChecks()
341341
*/
342342
protected function _fieldData(string $table): array
343343
{
344-
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT
345-
FROM INFORMATION_SCHEMA.COLUMNS
346-
WHERE TABLE_NAME= ' . $this->escape(($table));
344+
$sql = 'SELECT
345+
COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION,
346+
COLUMN_DEFAULT, IS_NULLABLE
347+
FROM INFORMATION_SCHEMA.COLUMNS
348+
WHERE TABLE_NAME= ' . $this->escape(($table));
347349

348350
if (($query = $this->query($sql)) === false) {
349351
throw new DatabaseException(lang('Database.failGetFieldData'));
@@ -362,6 +364,8 @@ protected function _fieldData(string $table): array
362364
$retVal[$i]->max_length = $query[$i]->CHARACTER_MAXIMUM_LENGTH > 0
363365
? $query[$i]->CHARACTER_MAXIMUM_LENGTH
364366
: $query[$i]->NUMERIC_PRECISION;
367+
368+
$retVal[$i]->nullable = $query[$i]->IS_NULLABLE !== 'NO';
365369
}
366370

367371
return $retVal;

tests/system/Database/Live/ForgeTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ public function testAddFields()
848848
'name' => [
849849
'type' => 'VARCHAR',
850850
'constraint' => 255,
851+
'null' => true,
851852
],
852853
'active' => [
853854
'type' => 'INTEGER',
@@ -889,7 +890,7 @@ public function testAddFields()
889890
'name' => 'name',
890891
'type' => 'varchar',
891892
'max_length' => 255,
892-
'nullable' => false,
893+
'nullable' => true,
893894
'default' => null,
894895
'primary_key' => 0,
895896
],
@@ -929,7 +930,7 @@ public function testAddFields()
929930
2 => [
930931
'name' => 'name',
931932
'type' => 'character varying',
932-
'nullable' => false,
933+
'nullable' => true,
933934
'default' => null,
934935
'max_length' => '255',
935936
],
@@ -965,7 +966,7 @@ public function testAddFields()
965966
'max_length' => null,
966967
'default' => null,
967968
'primary_key' => false,
968-
'nullable' => false,
969+
'nullable' => true,
969970
],
970971
3 => [
971972
'name' => 'active',
@@ -983,24 +984,28 @@ public function testAddFields()
983984
'type' => 'int',
984985
'default' => null,
985986
'max_length' => 10,
987+
'nullable' => false,
986988
],
987989
1 => [
988990
'name' => 'username',
989991
'type' => 'varchar',
990992
'default' => null,
991993
'max_length' => 255,
994+
'nullable' => false,
992995
],
993996
2 => [
994997
'name' => 'name',
995998
'type' => 'varchar',
996999
'default' => null,
9971000
'max_length' => 255,
1001+
'nullable' => true,
9981002
],
9991003
3 => [
10001004
'name' => 'active',
10011005
'type' => 'int',
10021006
'default' => '((0))', // Why?
10031007
'max_length' => 10,
1008+
'nullable' => false,
10041009
],
10051010
];
10061011
} elseif ($this->db->DBDriver === 'OCI8') {
@@ -1023,8 +1028,8 @@ public function testAddFields()
10231028
'name' => 'name',
10241029
'type' => 'VARCHAR2',
10251030
'max_length' => '255',
1026-
'default' => '',
1027-
'nullable' => false,
1031+
'default' => null,
1032+
'nullable' => true,
10281033
],
10291034
3 => [
10301035
'name' => 'active',

0 commit comments

Comments
 (0)