Alter indexes

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@29 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-07-05 05:09:01 +00:00
parent 720f5fc8a4
commit 0b6ab61436
3 changed files with 34 additions and 5 deletions

View file

@ -23,7 +23,7 @@ function optionlist($options, $selected = array(), $not_vals = false) {
$return .= '<optgroup label="' . htmlspecialchars($k) . '">';
}
foreach ((is_array($v) ? $v : array($k => $v)) as $key => $val) {
$checked = in_array(($not_vals ? $val : $key), (array) $selected);
$checked = in_array(($not_vals ? $val : $key), (array) $selected, true);
$return .= '<option' . ($not_vals ? '' : ' value="' . htmlspecialchars($key) . '"') . ($checked ? ' selected="selected"' : '') . '>' . htmlspecialchars($val) . '</option>';
}
if (is_array($v)) {

View file

@ -1,6 +1,36 @@
<?php
$index_types = array("PRIMARY", "UNIQUE", "INDEX", "FULLTEXT");
$indexes = indexes($_GET["indexes"]);
$fields = array_keys(fields($_GET["indexes"]));
if ($_POST) {
$alter = array();
foreach ($_POST["indexes"] as $index) {
if (in_array($index["type"], $index_types)) {
$columns = array();
ksort($index["columns"]);
foreach ($index["columns"] as $column) {
if (in_array($column, $fields, true)) {
$columns[count($columns) + 1] = $column;
}
}
if ($columns) {
foreach ($indexes as $name => $existing) {
if ($index["type"] == $existing["type"] && $existing["columns"] == $columns) {
unset($indexes[$name]);
continue 2;
}
}
$alter[] = "ADD $index[type]" . ($index["type"] == "PRIMARY" ? " KEY" : "") . " (" . implode(", ", array_map('idf_escape', $columns)) . ")";
}
}
}
foreach ($indexes as $name => $existing) {
$alter[] = "DROP INDEX " . idf_escape($name);
}
if (!$alter || mysql_query("ALTER TABLE " . idf_escape($_GET["indexes"]) . " " . implode(", ", $alter))) {
redirect($SELF . "table=" . urlencode($_GET["indexes"]), ($alter ? lang('Indexes has been altered.') : null));
}
$error = mysql_error();
}
page_header(lang('Indexes') . ': ' . htmlspecialchars($_GET["indexes"]));
@ -10,17 +40,16 @@ if ($_POST) {
echo "<p class='error'>" . lang('Unable to operate indexes') . ": " . htmlspecialchars($error) . "</p>\n";
$row = $_POST;
} else {
$row = array("indexes" => indexes($_GET["indexes"]));
$row = array("indexes" => $indexes);
}
?>
<form action="" method="post">
<table border="0" cellspacing="0" cellpadding="2">
<?php
$fields = array_keys(fields($_GET["indexes"]));
$j = 0;
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"]);
ksort($index["columns"]);
foreach ($index["columns"] as $i => $column) {
echo "<select name='indexes[$j][columns][$i]'><option></option>" . optionlist($fields, $column, "not_vals") . "</select>";
}

View file

@ -16,7 +16,7 @@ $indexes = indexes($_GET["table"]);
if ($indexes) {
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
foreach ($indexes as $index) {
sort($index["columns"]);
ksort($index["columns"]);
echo "<tr><td>$index[type]</td><td><i>" . implode("</i>, <i>", $index["columns"]) . "</i></td></tr>\n";
}
echo "</table>\n";