Separate backward keys
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@873 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
c325cbe02d
commit
e5de7ef853
|
@ -72,6 +72,14 @@ function adminer_select_links($table_status) {
|
||||||
return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . (isset($table_status["Engine"]) ? 'table=' : 'view=') . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
|
return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . (isset($table_status["Engine"]) ? 'table=' : 'view=') . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Find backward keys for table
|
||||||
|
* @param string
|
||||||
|
* @return array $return[$target_table][$key_name][$target_column] = $source_column;
|
||||||
|
*/
|
||||||
|
function adminer_backward_keys($table) {
|
||||||
|
return call_adminer('backward_keys', array(), $table);
|
||||||
|
}
|
||||||
|
|
||||||
/** Query printed in select before execution
|
/** Query printed in select before execution
|
||||||
* @param string query to be executed
|
* @param string query to be executed
|
||||||
* @return string
|
* @return string
|
||||||
|
|
|
@ -285,22 +285,7 @@ if (!$columns) {
|
||||||
}
|
}
|
||||||
$descriptions = adminer_row_descriptions($rows, $foreign_keys);
|
$descriptions = adminer_row_descriptions($rows, $foreign_keys);
|
||||||
|
|
||||||
//! Editor only
|
$backward_keys = adminer_backward_keys($_GET["select"]);
|
||||||
$backward_keys = array();
|
|
||||||
$result = $dbh->query("
|
|
||||||
SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
|
|
||||||
FROM information_schema.KEY_COLUMN_USAGE
|
|
||||||
WHERE TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . "
|
|
||||||
AND REFERENCED_TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . "
|
|
||||||
AND REFERENCED_TABLE_NAME = " . $dbh->quote($_GET["select"]) . "
|
|
||||||
ORDER BY ORDINAL_POSITION
|
|
||||||
");
|
|
||||||
if ($result) {
|
|
||||||
while ($row = $result->fetch_assoc()) {
|
|
||||||
$backward_keys[$row["TABLE_NAME"]][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
|
|
||||||
}
|
|
||||||
$result->free();
|
|
||||||
}
|
|
||||||
$table_names = array_keys($backward_keys);
|
$table_names = array_keys($backward_keys);
|
||||||
if ($table_names) {
|
if ($table_names) {
|
||||||
$table_names = array_combine($table_names, array_map('adminer_table_name', array_map('table_status', $table_names)));
|
$table_names = array_combine($table_names, array_map('adminer_table_name', array_map('table_status', $table_names)));
|
||||||
|
|
|
@ -40,6 +40,26 @@ function adminer_select_links($table_status) {
|
||||||
return call_adminer('select_links', "", $table_status);
|
return call_adminer('select_links', "", $table_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function adminer_backward_keys($table) {
|
||||||
|
global $dbh;
|
||||||
|
$return = array();
|
||||||
|
$result = $dbh->query("
|
||||||
|
SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
|
||||||
|
FROM information_schema.KEY_COLUMN_USAGE
|
||||||
|
WHERE TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . "
|
||||||
|
AND REFERENCED_TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . "
|
||||||
|
AND REFERENCED_TABLE_NAME = " . $dbh->quote($table) . "
|
||||||
|
ORDER BY ORDINAL_POSITION
|
||||||
|
");
|
||||||
|
if ($result) {
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$return[$row["TABLE_NAME"]][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
|
||||||
|
}
|
||||||
|
$result->free();
|
||||||
|
}
|
||||||
|
return call_adminer('backward_keys', $return, $table);
|
||||||
|
}
|
||||||
|
|
||||||
function adminer_select_query($query) {
|
function adminer_select_query($query) {
|
||||||
return call_adminer('select_query', "<!-- " . str_replace("--", "--><!--", $query) . " -->\n", $query);
|
return call_adminer('select_query', "<!-- " . str_replace("--", "--><!--", $query) . " -->\n", $query);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +84,7 @@ function adminer_row_descriptions($rows, $foreign_keys) {
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$ids[$row[$key]] = $dbh->quote($row[$key]);
|
$ids[$row[$key]] = $dbh->quote($row[$key]);
|
||||||
}
|
}
|
||||||
// select all descriptions
|
// uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow
|
||||||
$descriptions = array();
|
$descriptions = array();
|
||||||
$result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreign_key["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")");
|
$result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreign_key["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")");
|
||||||
while ($row = $result->fetch_row()) {
|
while ($row = $result->fetch_row()) {
|
||||||
|
@ -83,7 +103,7 @@ function adminer_row_descriptions($rows, $foreign_keys) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_select_val($val, $link) {
|
function adminer_select_val($val, $link) {
|
||||||
return call_adminer('select_val', ($link ? '<a href="' . $link . '">' . $val . '</a>' : ($val == "<i>NULL</i>" ? "" : $val)), $val, $link);
|
return call_adminer('select_val', ($link ? "<a href=\"$link\">$val</a>" : ($val == "<i>NULL</i>" ? "" : $val)), $val, $link);
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_message_query($query) {
|
function adminer_message_query($query) {
|
||||||
|
|
1
todo.txt
1
todo.txt
|
@ -14,6 +14,7 @@ Offer enum and set items in search - whisperer
|
||||||
Use event $intervals + microseconds in relative date functions
|
Use event $intervals + microseconds in relative date functions
|
||||||
Ability to select external style - list downloaded by JavaScript
|
Ability to select external style - list downloaded by JavaScript
|
||||||
Table list cache - SHOW TABLE STATUS is slow with big InnoDB tables
|
Table list cache - SHOW TABLE STATUS is slow with big InnoDB tables
|
||||||
|
Download external files (version checker and JUSH) from trusted HTTPS if Adminer runs in HTTPS (mixed-content warning)
|
||||||
? Column and table names auto-completition in SQL textarea
|
? Column and table names auto-completition in SQL textarea
|
||||||
? Save token also to cookie - for session expiration and login in other window
|
? Save token also to cookie - for session expiration and login in other window
|
||||||
? Save uploaded files after error to session variable instead of hidden field
|
? Save uploaded files after error to session variable instead of hidden field
|
||||||
|
|
Loading…
Reference in a new issue