diff --git a/functions.inc.php b/functions.inc.php index 9e9081a1..9bc80092 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -89,11 +89,14 @@ function foreign_keys($table) { $result->free(); preg_match_all("~CONSTRAINT `($pattern)` FOREIGN KEY \\(((?:`$pattern`,? ?)+)\\) REFERENCES `($pattern)`(?:\\.`($pattern)`)? \\(((?:`$pattern`,? ?)+)\\)~", $create_table, $matches, PREG_SET_ORDER); foreach ($matches as $match) { - $db = idf_unescape(strlen($match[4]) ? $match[3] : $match[4]); - $table = idf_unescape(strlen($match[4]) ? $match[4] : $match[3]); preg_match_all("~`($pattern)`~", $match[2], $source); preg_match_all("~`($pattern)`~", $match[5], $target); - $return[$match[1]] = array($db, $table, array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1])); + $return[$match[1]] = array( + "db" => idf_unescape(strlen($match[4]) ? $match[3] : $match[4]), + "table" => idf_unescape(strlen($match[4]) ? $match[4] : $match[3]), + "source" => array_map('idf_unescape', $source[1]), + "target" => array_map('idf_unescape', $target[1]), + ); } } return $return; diff --git a/select.inc.php b/select.inc.php index 18c78384..3a43cd26 100644 --- a/select.inc.php +++ b/select.inc.php @@ -113,7 +113,7 @@ for (var i=0; > i; i++) { $found_rows = $mysql->result($mysql->query(" SELECT FOUND_ROWS()")); // space for mysql.trace_mode $foreign_keys = array(); foreach (foreign_keys($_GET["select"]) as $foreign_key) { - foreach ($foreign_key[2] as $val) { + foreach ($foreign_key["source"] as $val) { $foreign_keys[$val][] = $foreign_key; } } @@ -122,10 +122,10 @@ for (var i=0; > i; i++) { // would be possible in earlier versions too, but only by examining all tables (in all databases) $result1 = $mysql->query("SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . $mysql->escape_string($_GET["db"]) . "' AND REFERENCED_TABLE_NAME = '" . $mysql->escape_string($_GET["select"]) . "' ORDER BY ORDINAL_POSITION"); while ($row1 = $result1->fetch_assoc()) { - $childs[$row1["CONSTRAINT_NAME"]][0] = $row1["TABLE_SCHEMA"]; - $childs[$row1["CONSTRAINT_NAME"]][1] = $row1["TABLE_NAME"]; - $childs[$row1["CONSTRAINT_NAME"]][2][] = $row1["REFERENCED_COLUMN_NAME"]; - $childs[$row1["CONSTRAINT_NAME"]][3][] = $row1["COLUMN_NAME"]; + $childs[$row1["CONSTRAINT_NAME"]]["db"] = $row1["TABLE_SCHEMA"]; + $childs[$row1["CONSTRAINT_NAME"]]["table"] = $row1["TABLE_NAME"]; + $childs[$row1["CONSTRAINT_NAME"]]["source"][] = $row1["REFERENCED_COLUMN_NAME"]; + $childs[$row1["CONSTRAINT_NAME"]]["target"][] = $row1["COLUMN_NAME"]; } $result1->free(); } @@ -146,12 +146,12 @@ for (var i=0; > i; i++) { } else { $val = (strlen(trim($val)) ? nl2br(htmlspecialchars($val)) : " "); foreach ((array) $foreign_keys[$key] as $foreign_key) { - if (count($foreign_keys[$key]) == 1 || count($foreign_key[2]) == 1) { + if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) { $val = '">' . "$val"; - foreach ($foreign_key[2] as $i => $source) { - $val = "&where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key[3][$i]) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]) . $val; + foreach ($foreign_key["source"] as $i => $source) { + $val = "&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]) . $val; } - $val = ' > i; i++) { } echo '
" . implode(", ", $foreign_key[2]) . " | "; - $link = (strlen($foreign_key[0]) ? "" . htmlspecialchars($foreign_key[0]) . "." : "") . htmlspecialchars($foreign_key[1]); - echo '$link(" . implode(", ", $foreign_key[3]) . ") | "; - echo '' . (!strlen($foreign_key[0]) ? '' . lang('Alter') . '' : ' ') . ' | '; + echo "" . implode(", ", $foreign_key["source"]) . " | "; + $link = (strlen($foreign_key["db"]) ? "" . htmlspecialchars($foreign_key["db"]) . "." : "") . htmlspecialchars($foreign_key["table"]); + echo '$link(" . implode(", ", $foreign_key["target"]) . ") | "; + echo '' . (!strlen($foreign_key["db"]) ? '' . lang('Alter') . '' : ' ') . ' | '; echo "