Permalink
Browse files

Alter indexes

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@29 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 720f5fc commit 0b6ab614363034ee1babf3ff6b5436eddd4f60f3 jakubvrana committed Jul 5, 2007
Showing with 34 additions and 5 deletions.
  1. +1 −1 functions.inc.php
  2. +32 −3 indexes.inc.php
  3. +1 −1 table.inc.php
View
2 functions.inc.php
@@ -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
35 indexes.inc.php
@@ -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 @@
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
2 table.inc.php
@@ -16,7 +16,7 @@
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";

0 comments on commit 0b6ab61

Please sign in to comment.