diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 6d1cc457..ebe8969d 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -88,12 +88,21 @@ class Adminer { /** Find backward keys for table * @param string - * @return array $return[$target_table][$key_name][$target_column] = $source_column; + * @param string + * @return array $return[$target_table]["keys"][$key_name][$target_column] = $source_column; $return[$target_table]["name"] = $this->tableName($target_table); */ - function backwardKeys($table) { + function backwardKeys($table, $tableName) { return array(); } + /** Print backward keys for row + * @param array result of $this->backwardKeys() + * @param array + * @return null + */ + function backwardKeysPrint($backwardKeys, $row) { + } + /** Query printed in select before execution * @param string query to be executed * @return string @@ -461,7 +470,7 @@ class Adminer {

printTables($missing); + $this->tablesPrint($missing); } } @@ -469,7 +478,7 @@ class Adminer { * @param string can be "db" if there is no database selected * @return null */ - function printTables($missing) { + function tablesPrint($missing) { global $connection; if ($missing != "db" && strlen(DB) && $connection->select_db(DB)) { $result = $connection->query("SHOW TABLES"); diff --git a/adminer/select.inc.php b/adminer/select.inc.php index a698e16d..ad77fdb6 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -174,16 +174,7 @@ if (!$columns) { : count($rows) ); - $backward_keys = $adminer->backwardKeys($TABLE); - $table_names = array(); - if ($backward_keys) { - foreach ($backward_keys as $key => $val) { - $val = $adminer->tableName(table_status($key)); - if (strlen($val)) { - $table_names[$key] = (preg_match('(^' . preg_quote($table_name) . '(:|\\s*-)?\\s+(.+))', $val, $match) ? $match[2] : $val); - } - } - } + $backward_keys = $adminer->backwardKeys($TABLE, $table_name); echo "\n"; echo "\n"; + echo ($backward_keys ? "
"; @@ -201,7 +192,7 @@ if (!$columns) { } next($select); } - echo ($table_names ? "" . lang('Relations') : "") . "
" . lang('Relations') : "") . "\n"; foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) { $unique_idf = implode('&', unique_idf($rows[$n], $indexes)); echo "" . (count($select) != count($group) || information_schema(DB) ? '' : " " . lang('edit') . ""); @@ -245,19 +236,7 @@ if (!$columns) { echo "$val"; } } - if ($table_names) { - echo ""; - foreach ($table_names as $table => $name) { - foreach ($backward_keys[$table] as $cols) { - $link = ME . 'select=' . urlencode($table); - $i = 0; - foreach ($cols as $column => $val) { - $link .= where_link($i++, $column, $rows[$n][$val]); - } - echo " $name"; - } - } - } + $adminer->backwardKeysPrint($backward_keys, $rows[$n]); echo "\n"; } echo "
\n"; diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index aebe2920..52e0d570 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -46,7 +46,7 @@ class Adminer { } } - function backwardKeys($table) { + function backwardKeys($table, $tableName) { global $connection; $return = array(); $result = $connection->query("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME @@ -57,12 +57,38 @@ AND REFERENCED_TABLE_NAME = " . $connection->quote($table) . " ORDER BY ORDINAL_POSITION"); //! requires MySQL 5 if ($result) { while ($row = $result->fetch_assoc()) { - $return[$row["TABLE_NAME"]][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"]; + $return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"]; + } + } + foreach ($return as $key => $val) { + $name = $this->tableName(table_status($key)); + if (strlen($name)) { + $search = preg_quote($tableName); + $separator = "(:|\\s*-)?\\s+"; + $return[$key]["name"] = (preg_match("(^$search$separator(.+)|^(.+?)$separator$search\$)", $name, $match) ? $match[2] . $match[3] : $name); + } else { + unset($return[$key]); } } return $return; } + function backwardKeysPrint($backwardKeys, $row) { + if ($backwardKeys) { + echo ""; + foreach ($backwardKeys as $table => $backwardKey) { + foreach ($backwardKey["keys"] as $cols) { + $link = ME . 'select=' . urlencode($table); + $i = 0; + foreach ($cols as $column => $val) { + $link .= where_link($i++, $column, $row[$val]); + } + echo " $backwardKey[name]"; + } + } + } + } + function selectQuery($query) { return "\n"; } @@ -389,11 +415,11 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5

printTables($missing); + $this->tablesPrint($missing); } } - function printTables($missing) { + function tablesPrint($missing) { if ($missing != "db") { $table_status = table_status(); if (!$table_status) {