Permalink
Browse files

Separate backward keys

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@873 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent c325cbe commit e5de7ef853620277172462f6fbc65fcedbab1323 jakubvrana committed Jul 22, 2009
Showing with 32 additions and 18 deletions.
  1. +8 −0 adminer/include/adminer.inc.php
  2. +1 −16 adminer/select.inc.php
  3. +22 −2 editor/include/adminer.inc.php
  4. +1 −0 todo.txt
@@ -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);
}
+/** 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
* @param string query to be executed
* @return string
View
@@ -285,22 +285,7 @@
}
$descriptions = adminer_row_descriptions($rows, $foreign_keys);
- //! Editor only
- $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();
- }
+ $backward_keys = adminer_backward_keys($_GET["select"]);
$table_names = array_keys($backward_keys);
if ($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);
}
+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) {
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) {
$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();
$result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreign_key["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")");
while ($row = $result->fetch_row()) {
@@ -83,7 +103,7 @@ function adminer_row_descriptions($rows, $foreign_keys) {
}
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) {
View
@@ -14,6 +14,7 @@ Offer enum and set items in search - whisperer
Use event $intervals + microseconds in relative date functions
Ability to select external style - list downloaded by JavaScript
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
? 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

0 comments on commit e5de7ef

Please sign in to comment.