]> git.joonet.de Git - adminer.git/commitdiff
Link tables and indexes from SQL command EXPLAIN
authorJakub Vrana <jakub@vrana.cz>
Wed, 13 Jul 2011 14:31:47 +0000 (16:31 +0200)
committerJakub Vrana <jakub@vrana.cz>
Wed, 13 Jul 2011 14:31:47 +0000 (16:31 +0200)
adminer/include/editing.inc.php
changes.txt

index a058de9238ed84c2435bc13a6f0461beaa787ea7..9964448e621de3e778ad05af47cde1a6e8991811 100644 (file)
@@ -18,9 +18,12 @@ function select($result, $connection2 = null, $href = "") {
                        echo "<thead><tr>";
                        for ($j=0; $j < count($row); $j++) {
                                $field = $result->fetch_field();
+                               $name = $field->name;
                                $orgtable = $field->orgtable;
                                $orgname = $field->orgname;
-                               if ($orgtable != "") {
+                               if ($href) { // MySQL EXPLAIN
+                                       $links[$j] = ($name == "table" ? "table=" : ($name == "possible_keys" ? "indexes=" : null));
+                               } elseif ($orgtable != "") {
                                        if (!isset($indexes[$orgtable])) {
                                                // find primary key in each table
                                                $indexes[$orgtable] = array();
@@ -42,7 +45,7 @@ function select($result, $connection2 = null, $href = "") {
                                        $blobs[$j] = true;
                                }
                                $types[$j] = $field->type;
-                               $name = h($field->name);
+                               $name = h($name);
                                echo "<th" . ($orgtable != "" || $field->name != $orgname ? " title='" . h(($orgtable != "" ? "$orgtable." : "") . $orgname) . "'" : "") . ">" . ($href ? "<a href='$href" . strtolower($name) . "' target='_blank' rel='noreferrer'>$name</a>" : $name);
                        }
                        echo "</thead>\n";
@@ -51,24 +54,26 @@ function select($result, $connection2 = null, $href = "") {
                foreach ($row as $key => $val) {
                        if (!isset($val)) {
                                $val = "<i>NULL</i>";
+                       } elseif ($blobs[$key] && !is_utf8($val)) {
+                               $val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>"; //! link to download
+                       } elseif (!strlen($val)) { // strlen - SQLite can return int
+                               $val = "&nbsp;"; // some content to print a border
                        } else {
-                               if ($blobs[$key] && !is_utf8($val)) {
-                                       $val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>"; //! link to download
-                               } elseif (!strlen($val)) { // strlen - SQLite can return int
-                                       $val = "&nbsp;"; // some content to print a border
-                               } else {
-                                       $val = h($val);
-                                       if ($types[$key] == 254) { // 254 - char
-                                               $val = "<code>$val</code>";
-                                       }
+                               $val = h($val);
+                               if ($types[$key] == 254) { // 254 - char
+                                       $val = "<code>$val</code>";
                                }
-                               if (isset($links[$key]) && !$columns[$links[$key]]) {
+                       }
+                       if (isset($links[$key]) && !$columns[$links[$key]]) {
+                               if ($href) { // MySQL EXPLAIN
+                                       $link = $links[$key] . urlencode($row[array_search("table=", $links)]);
+                               } else {
                                        $link = "edit=" . urlencode($links[$key]);
                                        foreach ($indexes[$links[$key]] as $col => $j) {
                                                $link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]);
                                        }
-                                       $val = "<a href='" . h(ME . $link) . "'>$val</a>";
                                }
+                               $val = "<a href='" . h(ME . $link) . "'>$val</a>";
                        }
                        echo "<td>$val";
                }
index 486d2374424c8cbf336acd32799370b91dfdc0c8..cf6464a0a770b3acab112fa64b83ad3028ef5c88 100644 (file)
@@ -11,6 +11,7 @@ Display column collation in tooltip
 Keyboard shortcuts: Alt+Shift+1 for homepage, Ctrl+Shift+Enter for Save and continue edit
 Show only errors with Webserver file SQL command
 Remember select export and import options
+Link tables and indexes from SQL command EXPLAIN (MySQL)
 Display error with all wrong SQL commands (MySQL)
 Display foreign keys from other schemas (PostgreSQL)
 Pagination support (Oracle)