]> git.joonet.de Git - adminer.git/commitdiff
Table relations
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 15 Jul 2009 14:56:27 +0000 (14:56 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 15 Jul 2009 14:56:27 +0000 (14:56 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@836 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/include/functions.inc.php
adminer/lang/cs.inc.php
adminer/select.inc.php
changes.txt

index e9a091b26025e244f4552defaffffb5642ead9dd..706f46ee58ff23a8d1e814c494668e320edc5f27 100644 (file)
@@ -81,6 +81,10 @@ function where_check($val) {
        return where($check);
 }
 
+function where_link($i, $column, $value) {
+       return "&amp;where%5B$i%5D%5Bcol%5D=" . urlencode($column) . "&amp;where%5B$i%5D%5Bop%5D=%3D&amp;where%5B$i%5D%5Bval%5D=" . urlencode($value);
+}
+
 function process_length($length) {
        global $enum_length;
        return (preg_match("~^\\s*(?:$enum_length)(?:\\s*,\\s*(?:$enum_length))*\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches) ? implode(",", $matches[0]) : preg_replace('~[^0-9,+-]~', '', $length));
index 60a6cf810eac24c10a14c60fa702194c24386f9c..475cf8b5f8912210f51e8bc720758077b384083a 100644 (file)
@@ -227,4 +227,5 @@ $translations = array(
        'Strings' => 'Řetězce',
        'Binary' => 'Binární',
        'Lists' => 'Seznamy',
+       'Relations' => 'Vztahy',
 );
index d17657343e5a32c5219b3cffdfbb69accceffdc3..8cd5c8c39e9e1b85d8f328945eefe72c53447431 100644 (file)
@@ -278,12 +278,29 @@ if (!$columns) {
                                }
                        }
                        
+                       //! 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($_GET["db"]) . "
+                               AND REFERENCED_TABLE_SCHEMA = " . $dbh->quote($_GET["db"]) . "
+                               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();
+                       }
+                       
                        echo "<table cellspacing='0' class='nowrap'>\n";
                        echo "<thead><tr><td><input type='checkbox' id='all-page' onclick='form_check(this, /check/);'>";
                        foreach ($rows[0] as $key => $val) {
                                echo '<th><a href="' . htmlspecialchars(remove_from_uri('(order|desc)[^=]*') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"] == array($key) && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . adminer_field_name($fields, $key) . '</a>';
                        }
-                       echo "</thead>\n";
+                       echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
                        foreach ($rows as $row) {
                                $unique_idf = implode('&amp;', unique_idf($row, $indexes)); //! don't use aggregation functions
                                echo '<tr' . odd() . '><td><input type="checkbox" name="check[]" value="' . $unique_idf . '" onclick="this.form[\'all\'].checked = false; form_uncheck(\'all-page\');">' . (count($select) != count($group) || information_schema($_GET["db"]) ? '' : ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&amp;' . $unique_idf . '">' . lang('edit') . '</a>');
@@ -312,9 +329,9 @@ if (!$columns) {
                                                foreach ((array) $foreign_keys[$key] as $foreign_key) {
                                                        if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
                                                                foreach ($foreign_key["source"] as $i => $source) {
-                                                                       $link .= "&where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key["target"][$i]) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]);
+                                                                       $link .= where_link($i, $foreign_key["target"][$i], $row[$source]);
                                                                }
-                                                               $link = htmlspecialchars((strlen($foreign_key["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), $SELF) : $SELF) . 'select=' . urlencode($foreign_key["table"]) . $link); // InnoDB supports non-UNIQUE keys
+                                                               $link = htmlspecialchars((strlen($foreign_key["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), $SELF) : $SELF) . 'select=' . urlencode($foreign_key["table"])) . $link; // InnoDB supports non-UNIQUE keys
                                                                break;
                                                        }
                                                }
@@ -322,6 +339,20 @@ if (!$columns) {
                                        }
                                        echo "<td>$val";
                                }
+                               if ($backward_keys) {
+                                       echo "<td>";
+                                       foreach ($backward_keys as $table => $keys) {
+                                               foreach ($keys as $columns) {
+                                                       echo ' <a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($table);
+                                                       $i = 0;
+                                                       foreach ($columns as $column => $val) {
+                                                               echo where_link($i, $column, $row[$val]);
+                                                               $i++;
+                                                       }
+                                                       echo '">' . htmlspecialchars($table) . '</a>'; //! adminer_table_name()
+                                               }
+                                       }
+                               }
                                echo "\n";
                        }
                        echo "</table>\n";
index 8440864cedd4bc3a8b768dfae7435dc933f4336f..d1782af012dd54791fc0646adc1c6a1da6c6ac53 100644 (file)
@@ -2,6 +2,7 @@ Adminer 2.0.0:
 Editor: User friendly data editor
 Customization: Adminer class
 E-mail sending
+Table relations
 Create single column foreign key in table structure
 Separate types to groups in table creation
 Show type in field name title (thanks to Jakub Sochor)