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();
|
$return = array();
|
||||||
$result = mysql_query("SHOW INDEX FROM " . idf_escape($table));
|
$result = mysql_query("SHOW INDEX FROM " . idf_escape($table));
|
||||||
while ($row = mysql_fetch_assoc($result)) {
|
while ($row = mysql_fetch_assoc($result)) {
|
||||||
$type = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
|
$return[$row["Key_name"]]["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"]]["columns"][$row["Seq_in_index"]] = $row["Column_name"];
|
||||||
}
|
}
|
||||||
mysql_free_result($result);
|
mysql_free_result($result);
|
||||||
return $return;
|
return $return;
|
||||||
|
@ -79,18 +79,16 @@ function foreign_keys($table) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function unique_idf($row, $indexes) {
|
function unique_idf($row, $indexes) {
|
||||||
foreach ($indexes as $type => $index) {
|
foreach ($indexes as $index) {
|
||||||
if ($type == "PRIMARY" || $type == "UNIQUE") {
|
if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") {
|
||||||
foreach ($index as $columns) {
|
$return = array();
|
||||||
$return = array();
|
foreach ($index["columns"] as $key) {
|
||||||
foreach ($columns as $key) {
|
if (!isset($row[$key])) {
|
||||||
if (!isset($row[$key])) {
|
continue 2;
|
||||||
continue 2;
|
|
||||||
}
|
|
||||||
$return[] = urlencode("where[$key]") . "=" . urlencode($row[$key]);
|
|
||||||
}
|
}
|
||||||
return $return;
|
$return[] = urlencode("where[$key]") . "=" . urlencode($row[$key]);
|
||||||
}
|
}
|
||||||
|
return $return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$return = array();
|
$return = array();
|
||||||
|
|
|
@ -18,17 +18,15 @@ if ($_POST) {
|
||||||
<?php
|
<?php
|
||||||
$fields = array_keys(fields($_GET["indexes"]));
|
$fields = array_keys(fields($_GET["indexes"]));
|
||||||
$j = 0;
|
$j = 0;
|
||||||
foreach ($row["indexes"] as $type => $index) {
|
foreach ($row["indexes"] as $index) {
|
||||||
foreach ($index as $columns) {
|
echo "<tr><td><select name='indexes[$j][type]'><option></option>" . optionlist($index_types, $index["type"], "not_vals") . "</select></td><td>";
|
||||||
echo "<tr><td><select name='indexes[$j][type]'><option></option>" . optionlist($index_types, $type, "not_vals") . "</select></td><td>";
|
sort($index["columns"]);
|
||||||
sort($columns);
|
foreach ($index["columns"] as $i => $column) {
|
||||||
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]'><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++;
|
|
||||||
}
|
}
|
||||||
|
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
|
//! JavaScript for adding more indexes and columns
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -15,11 +15,9 @@ echo "<h3>" . lang('Indexes') . "</h3>\n";
|
||||||
$indexes = indexes($_GET["table"]);
|
$indexes = indexes($_GET["table"]);
|
||||||
if ($indexes) {
|
if ($indexes) {
|
||||||
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
|
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
|
||||||
foreach ($indexes as $type => $index) {
|
foreach ($indexes as $index) {
|
||||||
foreach ($index as $columns) {
|
sort($index["columns"]);
|
||||||
sort($columns);
|
echo "<tr><td>$index[type]</td><td><i>" . implode("</i>, <i>", $index["columns"]) . "</i></td></tr>\n";
|
||||||
echo "<tr><td>$type</td><td><i>" . implode("</i>, <i>", $columns) . "</i></td></tr>\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue