Skip to content

Commit 65c6692

Browse files
authored
Merge pull request #8481 from kenjis/fix-getFieldData-property-order
fix: [OCI8][Postgre][SQLSRV][SQLite3] change order of properties returned by getFieldData()
2 parents e448aa7 + aa6978e commit 65c6692

File tree

7 files changed

+30
-30
lines changed

7 files changed

+30
-30
lines changed

system/Database/OCI8/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ protected function _fieldData(string $table): array
315315

316316
$retval[$i]->max_length = $length;
317317

318-
$retval[$i]->default = $query[$i]->DATA_DEFAULT;
319318
$retval[$i]->nullable = $query[$i]->NULLABLE === 'Y';
319+
$retval[$i]->default = $query[$i]->DATA_DEFAULT;
320320
}
321321

322322
return $retval;

system/Database/Postgre/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ protected function _fieldData(string $table): array
318318

319319
$retVal[$i]->name = $query[$i]->column_name;
320320
$retVal[$i]->type = $query[$i]->data_type;
321+
$retVal[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
321322
$retVal[$i]->nullable = $query[$i]->is_nullable === 'YES';
322323
$retVal[$i]->default = $query[$i]->column_default;
323-
$retVal[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
324324
}
325325

326326
return $retVal;

system/Database/SQLSRV/Connection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,15 @@ protected function _fieldData(string $table): array
357357
for ($i = 0, $c = count($query); $i < $c; $i++) {
358358
$retVal[$i] = new stdClass();
359359

360-
$retVal[$i]->name = $query[$i]->COLUMN_NAME;
361-
$retVal[$i]->type = $query[$i]->DATA_TYPE;
362-
$retVal[$i]->default = $query[$i]->COLUMN_DEFAULT;
360+
$retVal[$i]->name = $query[$i]->COLUMN_NAME;
361+
$retVal[$i]->type = $query[$i]->DATA_TYPE;
363362

364363
$retVal[$i]->max_length = $query[$i]->CHARACTER_MAXIMUM_LENGTH > 0
365364
? $query[$i]->CHARACTER_MAXIMUM_LENGTH
366365
: $query[$i]->NUMERIC_PRECISION;
367366

368367
$retVal[$i]->nullable = $query[$i]->IS_NULLABLE !== 'NO';
368+
$retVal[$i]->default = $query[$i]->COLUMN_DEFAULT;
369369
}
370370

371371
return $retVal;

system/Database/SQLite3/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ protected function _fieldData(string $table): array
272272
$retVal[$i]->name = $query[$i]->name;
273273
$retVal[$i]->type = $query[$i]->type;
274274
$retVal[$i]->max_length = null;
275+
$retVal[$i]->nullable = isset($query[$i]->notnull) && ! (bool) $query[$i]->notnull;
275276
$retVal[$i]->default = $query[$i]->dflt_value;
276277
// "pk" (either zero for columns that are not part of the primary key,
277278
// or the 1-based index of the column within the primary key).
278279
// https://www.sqlite.org/pragma.html#pragma_table_info
279280
$retVal[$i]->primary_key = ($query[$i]->pk === 0) ? 0 : 1;
280-
$retVal[$i]->nullable = isset($query[$i]->notnull) && ! (bool) $query[$i]->notnull;
281281
}
282282

283283
return $retVal;

tests/system/Database/Live/ForgeTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -953,30 +953,30 @@ public function testAddFields(): void
953953
0 => [
954954
'name' => 'id',
955955
'type' => 'integer',
956+
'max_length' => '32',
956957
'nullable' => false,
957958
'default' => "nextval('db_forge_test_fields_id_seq'::regclass)",
958-
'max_length' => '32',
959959
],
960960
1 => [
961961
'name' => 'username',
962962
'type' => 'character varying',
963+
'max_length' => '255',
963964
'nullable' => false,
964965
'default' => null,
965-
'max_length' => '255',
966966
],
967967
2 => [
968968
'name' => 'name',
969969
'type' => 'character varying',
970+
'max_length' => '255',
970971
'nullable' => true,
971972
'default' => null,
972-
'max_length' => '255',
973973
],
974974
3 => [
975975
'name' => 'active',
976976
'type' => 'integer',
977+
'max_length' => '32',
977978
'nullable' => false,
978979
'default' => '0',
979-
'max_length' => '32',
980980
],
981981
];
982982
} elseif ($this->db->DBDriver === 'SQLite3') {
@@ -985,64 +985,64 @@ public function testAddFields(): void
985985
'name' => 'id',
986986
'type' => 'INTEGER',
987987
'max_length' => null,
988+
'nullable' => true,
988989
'default' => null,
989990
'primary_key' => 1,
990-
'nullable' => true,
991991
],
992992
1 => [
993993
'name' => 'username',
994994
'type' => 'VARCHAR',
995995
'max_length' => null,
996+
'nullable' => false,
996997
'default' => null,
997998
'primary_key' => 0,
998-
'nullable' => false,
999999
],
10001000
2 => [
10011001
'name' => 'name',
10021002
'type' => 'VARCHAR',
10031003
'max_length' => null,
1004+
'nullable' => true,
10041005
'default' => null,
10051006
'primary_key' => 0,
1006-
'nullable' => true,
10071007
],
10081008
3 => [
10091009
'name' => 'active',
10101010
'type' => 'INTEGER',
10111011
'max_length' => null,
1012+
'nullable' => false,
10121013
'default' => '0',
10131014
'primary_key' => 0,
1014-
'nullable' => false,
10151015
],
10161016
];
10171017
} elseif ($this->db->DBDriver === 'SQLSRV') {
10181018
$expected = [
10191019
0 => [
10201020
'name' => 'id',
10211021
'type' => 'int',
1022-
'default' => null,
10231022
'max_length' => 10,
10241023
'nullable' => false,
1024+
'default' => null,
10251025
],
10261026
1 => [
10271027
'name' => 'username',
10281028
'type' => 'varchar',
1029-
'default' => null,
10301029
'max_length' => 255,
10311030
'nullable' => false,
1031+
'default' => null,
10321032
],
10331033
2 => [
10341034
'name' => 'name',
10351035
'type' => 'varchar',
1036-
'default' => null,
10371036
'max_length' => 255,
10381037
'nullable' => true,
1038+
'default' => null,
10391039
],
10401040
3 => [
10411041
'name' => 'active',
10421042
'type' => 'int',
1043-
'default' => '((0))', // Why?
10441043
'max_length' => 10,
10451044
'nullable' => false,
1045+
'default' => '((0))', // Why?
10461046
],
10471047
];
10481048
} elseif ($this->db->DBDriver === 'OCI8') {
@@ -1051,29 +1051,29 @@ public function testAddFields(): void
10511051
'name' => 'id',
10521052
'type' => 'NUMBER',
10531053
'max_length' => '11',
1054-
'default' => '"ORACLE"."ISEQ$$_80229".nextval', // Sequence id may change
10551054
'nullable' => false,
1055+
'default' => '"ORACLE"."ISEQ$$_80229".nextval', // Sequence id may change
10561056
],
10571057
1 => [
10581058
'name' => 'username',
10591059
'type' => 'VARCHAR2',
10601060
'max_length' => '255',
1061-
'default' => null,
10621061
'nullable' => false,
1062+
'default' => null,
10631063
],
10641064
2 => [
10651065
'name' => 'name',
10661066
'type' => 'VARCHAR2',
10671067
'max_length' => '255',
1068-
'default' => null,
10691068
'nullable' => true,
1069+
'default' => null,
10701070
],
10711071
3 => [
10721072
'name' => 'active',
10731073
'type' => 'NUMBER',
10741074
'max_length' => '11',
1075-
'default' => '0 ', // Why?
10761075
'nullable' => false,
1076+
'default' => '0 ', // Why?
10771077
],
10781078
];
10791079

tests/system/Database/Live/OCI8/GetFieldDataTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,57 +50,57 @@ public function testGetFieldData(): void
5050
'name' => 'id',
5151
'type' => 'NUMBER',
5252
'max_length' => '11',
53+
'nullable' => false,
5354
'default' => $idDefault, // The default value is not defined.
5455
// 'primary_key' => 1,
55-
'nullable' => false,
5656
],
5757
(object) [
5858
'name' => 'text_not_null',
5959
'type' => 'VARCHAR2',
6060
'max_length' => '64',
61+
'nullable' => false,
6162
'default' => null, // The default value is not defined.
6263
// 'primary_key' => 0,
63-
'nullable' => false,
6464
],
6565
(object) [
6666
'name' => 'text_null',
6767
'type' => 'VARCHAR2',
6868
'max_length' => '64',
69+
'nullable' => true,
6970
'default' => null, // The default value is not defined.
7071
// 'primary_key' => 0,
71-
'nullable' => true,
7272
],
7373
(object) [
7474
'name' => 'int_default_0',
7575
'type' => 'NUMBER',
7676
'max_length' => '11',
77+
'nullable' => false,
7778
'default' => '0 ', // int 0
7879
// 'primary_key' => 0,
79-
'nullable' => false,
8080
],
8181
(object) [
8282
'name' => 'text_default_null',
8383
'type' => 'VARCHAR2',
8484
'max_length' => '64',
85+
'nullable' => true,
8586
'default' => 'NULL ', // NULL value
8687
// 'primary_key' => 0,
87-
'nullable' => true,
8888
],
8989
(object) [
9090
'name' => 'text_default_text_null',
9191
'type' => 'VARCHAR2',
9292
'max_length' => '64',
93+
'nullable' => false,
9394
'default' => "'null' ", // string "null"
9495
// 'primary_key' => 0,
95-
'nullable' => false,
9696
],
9797
(object) [
9898
'name' => 'text_default_abc',
9999
'type' => 'VARCHAR2',
100100
'max_length' => '64',
101+
'nullable' => false,
101102
'default' => "'abc' ", // string "abc"
102103
// 'primary_key' => 0,
103-
'nullable' => false,
104104
],
105105
]), true);
106106
$names = array_column($expected, 'name');

user_guide_src/source/database/metadata.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ database:
100100
- ``name`` - column name
101101
- ``type`` - the type of the column
102102
- ``max_length`` - maximum length of the column
103-
- ``primary_key`` - integer ``1`` if the column is a primary key (all integer ``1``, even if there are multiple primary keys), otherwise integer ``0`` (This field is currently only available for ``MySQLi`` and ``SQLite3``)
104103
- ``nullable`` - boolean ``true`` if the column is nullable, otherwise boolean ``false``
105104
- ``default`` - the default value
105+
- ``primary_key`` - integer ``1`` if the column is a primary key (all integer ``1``, even if there are multiple primary keys), otherwise integer ``0`` (This field is currently only available for ``MySQLi`` and ``SQLite3``)
106106

107107
.. note:: Since v4.4.0, SQLSRV supported ``nullable``.
108108

0 commit comments

Comments
 (0)