Restructure indexes
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@28 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
88e1dafdf2
commit
720f5fc8a4
|
@ -56,8 +56,8 @@ function indexes($table) {
|
|||
$return = array();
|
||||
$result = mysql_query("SHOW INDEX FROM " . idf_escape($table));
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$type = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
|
||||
$return[$type][$row["Key_name"]][$row["Seq_in_index"]] = $row["Column_name"];
|
||||
$return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
|
||||
$return[$row["Key_name"]]["columns"][$row["Seq_in_index"]] = $row["Column_name"];
|
||||
}
|
||||
mysql_free_result($result);
|
||||
return $return;
|
||||
|
@ -79,18 +79,16 @@ function foreign_keys($table) {
|
|||
}
|
||||
|
||||
function unique_idf($row, $indexes) {
|
||||
foreach ($indexes as $type => $index) {
|
||||
if ($type == "PRIMARY" || $type == "UNIQUE") {
|
||||
foreach ($index as $columns) {
|
||||
$return = array();
|
||||
foreach ($columns as $key) {
|
||||
if (!isset($row[$key])) {
|
||||
continue 2;
|
||||
}
|
||||
$return[] = urlencode("where[$key]") . "=" . urlencode($row[$key]);
|
||||
foreach ($indexes as $index) {
|
||||
if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") {
|
||||
$return = array();
|
||||
foreach ($index["columns"] as $key) {
|
||||
if (!isset($row[$key])) {
|
||||
continue 2;
|
||||
}
|
||||
return $return;
|
||||
$return[] = urlencode("where[$key]") . "=" . urlencode($row[$key]);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
$return = array();
|
||||
|
|
|
@ -18,17 +18,15 @@ if ($_POST) {
|
|||
<?php
|
||||
$fields = array_keys(fields($_GET["indexes"]));
|
||||
$j = 0;
|
||||
foreach ($row["indexes"] as $type => $index) {
|
||||
foreach ($index as $columns) {
|
||||
echo "<tr><td><select name='indexes[$j][type]'><option></option>" . optionlist($index_types, $type, "not_vals") . "</select></td><td>";
|
||||
sort($columns);
|
||||
foreach ($columns as $i => $column) {
|
||||
echo "<select name='indexes[$j][columns][$i]'><option></option>" . optionlist($fields, $column, "not_vals") . "</select>";
|
||||
}
|
||||
echo "<select name='indexes[$j][columns][" . ($i+1) . "]'><option></option>" . optionlist($fields, array(), "not_vals") . "</select>";
|
||||
echo "</td></tr>\n";
|
||||
$j++;
|
||||
foreach ($row["indexes"] as $index) {
|
||||
echo "<tr><td><select name='indexes[$j][type]'><option></option>" . optionlist($index_types, $index["type"], "not_vals") . "</select></td><td>";
|
||||
sort($index["columns"]);
|
||||
foreach ($index["columns"] as $i => $column) {
|
||||
echo "<select name='indexes[$j][columns][$i]'><option></option>" . optionlist($fields, $column, "not_vals") . "</select>";
|
||||
}
|
||||
echo "<select name='indexes[$j][columns][" . ($i+1) . "]'><option></option>" . optionlist($fields, array(), "not_vals") . "</select>";
|
||||
echo "</td></tr>\n";
|
||||
$j++;
|
||||
}
|
||||
//! JavaScript for adding more indexes and columns
|
||||
?>
|
||||
|
|
|
@ -15,11 +15,9 @@ echo "<h3>" . lang('Indexes') . "</h3>\n";
|
|||
$indexes = indexes($_GET["table"]);
|
||||
if ($indexes) {
|
||||
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
|
||||
foreach ($indexes as $type => $index) {
|
||||
foreach ($index as $columns) {
|
||||
sort($columns);
|
||||
echo "<tr><td>$type</td><td><i>" . implode("</i>, <i>", $columns) . "</i></td></tr>\n";
|
||||
}
|
||||
foreach ($indexes as $index) {
|
||||
sort($index["columns"]);
|
||||
echo "<tr><td>$index[type]</td><td><i>" . implode("</i>, <i>", $index["columns"]) . "</i></td></tr>\n";
|
||||
}
|
||||
echo "</table>\n";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue