From 0b6ab614363034ee1babf3ff6b5436eddd4f60f3 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Thu, 5 Jul 2007 05:09:01 +0000 Subject: [PATCH] Alter indexes git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@29 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- functions.inc.php | 2 +- indexes.inc.php | 35 ++++++++++++++++++++++++++++++++--- table.inc.php | 2 +- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index 6c5cf088..dba5cdb7 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -23,7 +23,7 @@ function optionlist($options, $selected = array(), $not_vals = false) { $return .= ''; } 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 .= '' . htmlspecialchars($val) . ''; } if (is_array($v)) { diff --git a/indexes.inc.php b/indexes.inc.php index 6f96806a..f43f8bb0 100644 --- a/indexes.inc.php +++ b/indexes.inc.php @@ -1,6 +1,36 @@ $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 "

" . lang('Unable to operate indexes') . ": " . htmlspecialchars($error) . "

\n"; $row = $_POST; } else { - $row = array("indexes" => indexes($_GET["indexes"])); + $row = array("indexes" => $indexes); } ?>
"; - sort($index["columns"]); + ksort($index["columns"]); foreach ($index["columns"] as $i => $column) { echo ""; } diff --git a/table.inc.php b/table.inc.php index b29ffb7c..b560d57e 100644 --- a/table.inc.php +++ b/table.inc.php @@ -16,7 +16,7 @@ $indexes = indexes($_GET["table"]); if ($indexes) { echo "\n"; foreach ($indexes as $index) { - sort($index["columns"]); + ksort($index["columns"]); echo "\n"; } echo "
$index[type]" . implode(", ", $index["columns"]) . "
\n";