]> git.joonet.de Git - adminer.git/commitdiff
Separate backward keys
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 22 Jul 2009 11:04:03 +0000 (11:04 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 22 Jul 2009 11:04:03 +0000 (11:04 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@873 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/include/adminer.inc.php
adminer/select.inc.php
editor/include/adminer.inc.php
todo.txt

index 86f4738f4ed0d6e018b9411699ad76604971473c..61437d81278beb3e0bb5890f8e7fae6959fa4cbb 100644 (file)
@@ -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
index 630c7b7ab097acfed37b27a484f134779e4e1cc4..9a029b21b47ad80f882ad8c3fe113ea1a9ada113 100644 (file)
@@ -285,22 +285,7 @@ if (!$columns) {
                        }
                        $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)));
index 09a0027154ba872bf83953bcf2350017b939b390..7e7cf47d028875e118b69f5c5843fbe13f152508 100644 (file)
@@ -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) {
index 5f8f4602f0c149c858c263fe54003e75f77a1822..deb098651c1cf67526d3dc4ba4b94b891da8a9c5 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -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