Skip to content

Commit e878a83

Browse files
Merge pull request #19468 from kamil-tekiela/Fix-bug-in-Relation
Fix bug in Relation Fixes #19467
2 parents d931426 + fb4b451 commit e878a83

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/ConfigStorage/Relation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ public function getDisplayField(string $db, string $table): string
479479
. ' WHERE `db_name` = ' . $this->dbi->quoteString($db)
480480
. ' AND `table_name` = ' . $this->dbi->quoteString($table);
481481

482-
$row = $this->dbi->fetchSingleRow($dispQuery, DatabaseInterface::FETCH_ASSOC, ConnectionType::ControlUser);
483-
if ($row['display_field'] !== null) {
484-
return $row['display_field'];
482+
$displayField = $this->dbi->fetchValue($dispQuery, 0, ConnectionType::ControlUser);
483+
if (is_string($displayField)) {
484+
return $displayField;
485485
}
486486
}
487487

tests/unit/ConfigStorage/RelationTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,46 @@ public function testPMAGetDisplayField(): void
6565
'',
6666
$relation->getDisplayField($db, $table),
6767
);
68+
69+
$relationParameters = RelationParameters::fromArray([
70+
'displaywork' => true,
71+
'db' => 'pmadb',
72+
'table_info' => 'table_info',
73+
'relation' => 'relation',
74+
]);
75+
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, $relationParameters);
76+
77+
$dummyDbi->addResult(
78+
'SELECT `display_field` FROM `pmadb`.`table_info`'
79+
. ' WHERE `db_name` = \'information_schema\' AND `table_name` = \'PMA\'',
80+
[['TABLE_COMMENT']],
81+
['display_field'],
82+
);
83+
$db = 'information_schema';
84+
$table = 'PMA';
85+
self::assertSame(
86+
'TABLE_COMMENT',
87+
$relation->getDisplayField($db, $table),
88+
);
89+
90+
$dummyDbi->addResult(
91+
'SELECT `display_field` FROM `pmadb`.`table_info`'
92+
. ' WHERE `db_name` = \'information_schema\' AND `table_name` = \'NON_EXISTING_TABLE\'',
93+
[],
94+
);
95+
$dummyDbi->addResult(
96+
'SELECT *, `COLUMN_NAME` AS `Field`, `COLUMN_TYPE` AS `Type`, `COLLATION_NAME` AS `Collation`,'
97+
. ' `IS_NULLABLE` AS `Null`, `COLUMN_KEY` AS `Key`, `COLUMN_DEFAULT` AS `Default`, `EXTRA` AS `Extra`,'
98+
. ' `PRIVILEGES` AS `Privileges`, `COLUMN_COMMENT` AS `Comment` FROM `information_schema`.`COLUMNS`'
99+
. ' WHERE `TABLE_SCHEMA` = \'information_schema\' AND `TABLE_NAME` = \'NON_EXISTING_TABLE\'',
100+
[],
101+
);
102+
$db = 'information_schema';
103+
$table = 'NON_EXISTING_TABLE';
104+
self::assertSame(
105+
'',
106+
$relation->getDisplayField($db, $table),
107+
);
68108
}
69109

70110
/**

0 commit comments

Comments
 (0)