From: jakubvrana Date: Wed, 15 Jul 2009 14:56:27 +0000 (+0000) Subject: Table relations X-Git-Tag: v3.0.0~691 X-Git-Url: https://git.joonet.de/?a=commitdiff_plain;h=c42c46a2d492a1668ac586e148659e4533b06a3f;p=adminer.git Table relations git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@836 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index e9a091b2..706f46ee 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -81,6 +81,10 @@ function where_check($val) { return where($check); } +function where_link($i, $column, $value) { + return "&where%5B$i%5D%5Bcol%5D=" . urlencode($column) . "&where%5B$i%5D%5Bop%5D=%3D&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)); diff --git a/adminer/lang/cs.inc.php b/adminer/lang/cs.inc.php index 60a6cf81..475cf8b5 100644 --- a/adminer/lang/cs.inc.php +++ b/adminer/lang/cs.inc.php @@ -227,4 +227,5 @@ $translations = array( 'Strings' => 'Řetězce', 'Binary' => 'Binární', 'Lists' => 'Seznamy', + 'Relations' => 'Vztahy', ); diff --git a/adminer/select.inc.php b/adminer/select.inc.php index d1765734..8cd5c8c3 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -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 "\n"; echo "\n"; + echo ($backward_keys ? "
"; foreach ($rows[0] as $key => $val) { echo '' . adminer_field_name($fields, $key) . ''; } - echo "
" . lang('Relations') : "") . "\n"; foreach ($rows as $row) { $unique_idf = implode('&', unique_idf($row, $indexes)); //! don't use aggregation functions echo '' . (count($select) != count($group) || information_schema($_GET["db"]) ? '' : ' ' . lang('edit') . ''); @@ -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 "$val"; } + if ($backward_keys) { + echo ""; + foreach ($backward_keys as $table => $keys) { + foreach ($keys as $columns) { + echo ' ' . htmlspecialchars($table) . ''; //! adminer_table_name() + } + } + } echo "\n"; } echo "
\n"; diff --git a/changes.txt b/changes.txt index 8440864c..d1782af0 100644 --- a/changes.txt +++ b/changes.txt @@ -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)