Skip to content

Commit ad3072c

Browse files
authored
Merge pull request #19568 from faissaloux/fix/table-structure-columns-order
Fix columns order in Table Structure Fixes #19558
1 parent b2cc10a commit ad3072c

13 files changed

+52
-32
lines changed

src/Query/Generator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ public static function getColumns(
154154
. ' = ' . $quotedDatabase
155155
. ' AND `TABLE_NAME` ' . Util::getCollateForIS()
156156
. ' = ' . $quotedTable
157-
. ($quotedColumn !== null ? ' AND `COLUMN_NAME` = ' . $quotedColumn : '');
157+
. ($quotedColumn !== null ? ' AND `COLUMN_NAME` = ' . $quotedColumn : '')
158+
. ' ORDER BY `ORDINAL_POSITION`';
158159
}
159160

160161
public static function getColumnNamesAndTypes(
@@ -168,7 +169,8 @@ public static function getColumnNamesAndTypes(
168169
. ' WHERE `TABLE_SCHEMA` ' . Util::getCollateForIS()
169170
. ' = ' . $quotedDatabase
170171
. ' AND `TABLE_NAME` ' . Util::getCollateForIS()
171-
. ' = ' . $quotedTable;
172+
. ' = ' . $quotedTable
173+
. ' ORDER BY `ORDINAL_POSITION`';
172174
}
173175

174176
public static function getInformationSchemaRoutinesRequest(

tests/unit/ConfigStorage/RelationTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public function testPMAGetDisplayField(): void
6464
. ' `COLUMN_COMMENT` AS `Comment`'
6565
. ' FROM `information_schema`.`COLUMNS`'
6666
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'information_schema\' AND'
67-
. ' `TABLE_NAME` COLLATE utf8_bin = \'PMA\'',
67+
. ' `TABLE_NAME` COLLATE utf8_bin = \'PMA\''
68+
. ' ORDER BY `ORDINAL_POSITION`',
6869
[],
6970
);
7071

@@ -108,7 +109,8 @@ public function testPMAGetDisplayField(): void
108109
. ' `COLUMN_COMMENT` AS `Comment`'
109110
. ' FROM `information_schema`.`COLUMNS`'
110111
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'information_schema\' AND'
111-
. ' `TABLE_NAME` COLLATE utf8_bin = \'NON_EXISTING_TABLE\'',
112+
. ' `TABLE_NAME` COLLATE utf8_bin = \'NON_EXISTING_TABLE\''
113+
. ' ORDER BY `ORDINAL_POSITION`',
112114
[],
113115
);
114116
$db = 'information_schema';

tests/unit/Controllers/BrowseForeignersControllerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public function testBrowseForeignValues(): void
7474
. ' `COLUMN_COMMENT` AS `Comment`'
7575
. ' FROM `information_schema`.`COLUMNS`'
7676
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'\' AND `TABLE_NAME`'
77-
. ' COLLATE utf8_bin = \'actor\'',
77+
. ' COLLATE utf8_bin = \'actor\''
78+
. ' ORDER BY `ORDINAL_POSITION`',
7879
[
7980
['actor_id', 'smallint(5) unsigned', null, 'NO', 'PRI', null, 'auto_increment', '', ''],
8081
['first_name', 'varchar(45)', null, 'NO', '', null, '', '', ''],

tests/unit/Controllers/Import/ImportControllerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public function testIndexParametrized(): void
8585
. ' `COLUMN_COMMENT` AS `Comment`'
8686
. ' FROM `information_schema`.`COLUMNS`'
8787
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'pma_test\' AND'
88-
. ' `TABLE_NAME` COLLATE utf8_bin = \'table1\'',
88+
. ' `TABLE_NAME` COLLATE utf8_bin = \'table1\''
89+
. ' ORDER BY `ORDINAL_POSITION`',
8990
[],
9091
);
9192

tests/unit/Controllers/Sql/EnumValuesControllerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testGetEnumValuesError(): void
4545
. ' `COLUMN_COMMENT` AS `Comment`'
4646
. ' FROM `information_schema`.`COLUMNS`'
4747
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'cvv\' AND `TABLE_NAME`'
48-
. ' COLLATE utf8_bin = \'enums\' AND `COLUMN_NAME` = \'set\'', false);
48+
. ' COLLATE utf8_bin = \'enums\' AND `COLUMN_NAME` = \'set\' ORDER BY `ORDINAL_POSITION`', false);
4949
$this->dummyDbi->addResult('SHOW INDEXES FROM `cvv`.`enums`', false);
5050

5151
Current::$database = 'cvv';
@@ -90,7 +90,8 @@ public function testGetEnumValuesSuccess(): void
9090
. ' `COLUMN_COMMENT` AS `Comment`'
9191
. ' FROM `information_schema`.`COLUMNS`'
9292
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'cvv\' AND `TABLE_NAME` COLLATE utf8_bin = \'enums\''
93-
. ' AND `COLUMN_NAME` = \'set\'',
93+
. ' AND `COLUMN_NAME` = \'set\''
94+
. ' ORDER BY `ORDINAL_POSITION`',
9495
[
9596
[
9697
'set',

tests/unit/Controllers/Sql/SetValuesControllerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testError(): void
4545
. ' `COLUMN_COMMENT` AS `Comment`'
4646
. ' FROM `information_schema`.`COLUMNS`'
4747
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'cvv\' AND `TABLE_NAME`'
48-
. ' COLLATE utf8_bin = \'enums\' AND `COLUMN_NAME` = \'set\'', false);
48+
. ' COLLATE utf8_bin = \'enums\' AND `COLUMN_NAME` = \'set\' ORDER BY `ORDINAL_POSITION`', false);
4949
$this->dummyDbi->addResult('SHOW INDEXES FROM `cvv`.`enums`', false);
5050

5151
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
@@ -90,7 +90,8 @@ public function testSuccess(): void
9090
. ' `COLUMN_COMMENT` AS `Comment`'
9191
. ' FROM `information_schema`.`COLUMNS`'
9292
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'cvv\' AND `TABLE_NAME` COLLATE utf8_bin = \'enums\''
93-
. ' AND `COLUMN_NAME` = \'set\'',
93+
. ' AND `COLUMN_NAME` = \'set\''
94+
. ' ORDER BY `ORDINAL_POSITION`',
9495
[
9596
[
9697
'set',

tests/unit/Controllers/Table/CreateControllerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public function testCreateController(): void
4040
. ' `COLUMN_COMMENT` AS `Comment`'
4141
. ' FROM `information_schema`.`COLUMNS`'
4242
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'test_db\' AND'
43-
. ' `TABLE_NAME` COLLATE utf8_bin = \'new_test_table\'',
43+
. ' `TABLE_NAME` COLLATE utf8_bin = \'new_test_table\''
44+
. ' ORDER BY `ORDINAL_POSITION`',
4445
false,
4546
);
4647
$dummyDbi->addResult(
@@ -50,7 +51,8 @@ public function testCreateController(): void
5051
. ' `COLUMN_COMMENT` AS `Comment`'
5152
. ' FROM `information_schema`.`COLUMNS`'
5253
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'test_db\' AND'
53-
. ' `TABLE_NAME` COLLATE utf8_bin = \'new_test_table\'',
54+
. ' `TABLE_NAME` COLLATE utf8_bin = \'new_test_table\''
55+
. ' ORDER BY `ORDINAL_POSITION`',
5456
false,
5557
);
5658
$dummyDbi->addResult('SHOW CREATE TABLE `test_db`.`new_test_table`', false);

tests/unit/Controllers/Table/GetFieldControllerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public function testGetFieldController(): void
4242
. ' `COLUMN_COMMENT` AS `Comment`'
4343
. ' FROM `information_schema`.`COLUMNS`'
4444
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'test_db\' AND'
45-
. ' `TABLE_NAME` COLLATE utf8_bin = \'table_with_blob\'',
45+
. ' `TABLE_NAME` COLLATE utf8_bin = \'table_with_blob\''
46+
. ' ORDER BY `ORDINAL_POSITION`',
4647
[
4748
['id', 'int(11)', null, 'NO', 'PRI', null, 'auto_increment', '', ''],
4849
['file', 'blob', null, 'NO', '', null, '', '', ''],

tests/unit/DatabaseInterfaceTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ public function testGetColumn(): void
865865
. ' FROM `information_schema`.`COLUMNS`'
866866
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'test_db\' AND'
867867
. ' `TABLE_NAME` COLLATE utf8_bin = \'test_table\''
868-
. ' AND `COLUMN_NAME` = \'test_column\'',
868+
. ' AND `COLUMN_NAME` = \'test_column\''
869+
. ' ORDER BY `ORDINAL_POSITION`',
869870
[['test_column', 'varchar(45)', null, 'NO', '', null, '', '', '']],
870871
['Field', 'Type', 'Collation', 'Null', 'Key', 'Default', 'Extra', 'Privileges', 'Comment'],
871872
);
@@ -889,7 +890,8 @@ public function testGetColumnWithFullColumn(): void
889890
. ' FROM `information_schema`.`COLUMNS`'
890891
. ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'test_db\' AND'
891892
. ' `TABLE_NAME` COLLATE utf8_bin = \'test_table\''
892-
. ' AND `COLUMN_NAME` = \'test_column\'',
893+
. ' AND `COLUMN_NAME` = \'test_column\''
894+
. ' ORDER BY `ORDINAL_POSITION`',
893895
// phpcs:ignore Generic.Files.LineLength.TooLong
894896
[['test_column', 'varchar(45)', 'utf8mb4_general_ci', 'NO', '', null, '', 'select,insert,update,references', '']],
895897
['Field', 'Type', 'Collation', 'Null', 'Key', 'Default', 'Extra', 'Privileges', 'Comment'],

tests/unit/Query/GeneratorTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public function testGetColumnsSql(): void
2222
. ' `IS_NULLABLE` AS `Null`, `COLUMN_KEY` AS `Key`, `COLUMN_DEFAULT` AS `Default`,'
2323
. ' `EXTRA` AS `Extra`, `PRIVILEGES` AS `Privileges`, `COLUMN_COMMENT` AS `Comment`'
2424
. ' FROM `information_schema`.`COLUMNS` WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'mydb\''
25-
. ' AND `TABLE_NAME` COLLATE utf8_bin = \'mytable\'',
25+
. ' AND `TABLE_NAME` COLLATE utf8_bin = \'mytable\''
26+
. ' ORDER BY `ORDINAL_POSITION`',
2627
Generator::getColumns(
2728
"'mydb'",
2829
"'mytable'",
@@ -33,7 +34,8 @@ public function testGetColumnsSql(): void
3334
. ' `IS_NULLABLE` AS `Null`, `COLUMN_KEY` AS `Key`, `COLUMN_DEFAULT` AS `Default`,'
3435
. ' `EXTRA` AS `Extra`, `PRIVILEGES` AS `Privileges`, `COLUMN_COMMENT` AS `Comment`'
3536
. ' FROM `information_schema`.`COLUMNS` WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'mydb\''
36-
. ' AND `TABLE_NAME` COLLATE utf8_bin = \'mytable\' AND `COLUMN_NAME` = \'_idcolumn\'',
37+
. ' AND `TABLE_NAME` COLLATE utf8_bin = \'mytable\' AND `COLUMN_NAME` = \'_idcolumn\''
38+
. ' ORDER BY `ORDINAL_POSITION`',
3739
Generator::getColumns(
3840
"'mydb'",
3941
"'mytable'",
@@ -45,7 +47,8 @@ public function testGetColumnsSql(): void
4547
. ' `IS_NULLABLE` AS `Null`, `COLUMN_KEY` AS `Key`, `COLUMN_DEFAULT` AS `Default`,'
4648
. ' `EXTRA` AS `Extra`, `PRIVILEGES` AS `Privileges`, `COLUMN_COMMENT` AS `Comment`'
4749
. ' FROM `information_schema`.`COLUMNS` WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'mydb\''
48-
. ' AND `TABLE_NAME` COLLATE utf8_bin = \'mytable\'',
50+
. ' AND `TABLE_NAME` COLLATE utf8_bin = \'mytable\''
51+
. ' ORDER BY `ORDINAL_POSITION`',
4952
Generator::getColumns(
5053
"'mydb'",
5154
"'mytable'",
@@ -57,7 +60,8 @@ public function testGetColumnsSql(): void
5760
. ' `IS_NULLABLE` AS `Null`, `COLUMN_KEY` AS `Key`, `COLUMN_DEFAULT` AS `Default`,'
5861
. ' `EXTRA` AS `Extra`, `PRIVILEGES` AS `Privileges`, `COLUMN_COMMENT` AS `Comment`'
5962
. ' FROM `information_schema`.`COLUMNS` WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'mydb\''
60-
. ' AND `TABLE_NAME` COLLATE utf8_bin = \'mytable\' AND `COLUMN_NAME` = \'_idcolumn\'',
63+
. ' AND `TABLE_NAME` COLLATE utf8_bin = \'mytable\' AND `COLUMN_NAME` = \'_idcolumn\''
64+
. ' ORDER BY `ORDINAL_POSITION`',
6165
Generator::getColumns(
6266
"'mydb'",
6367
"'mytable'",

0 commit comments

Comments
 (0)