Skip to content

Commit fb4b451

Browse files
committed
Fix bug in Relation
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent df70994 commit fb4b451

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
@@ -477,9 +477,9 @@ public function getDisplayField(string $db, string $table): string
477477
. ' WHERE `db_name` = ' . $this->dbi->quoteString($db)
478478
. ' AND `table_name` = ' . $this->dbi->quoteString($table);
479479

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

tests/unit/ConfigStorage/RelationTest.php

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

67107
/**

0 commit comments

Comments
 (0)