]> git.joonet.de Git - adminer.git/commitdiff
Alter indexes
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Thu, 5 Jul 2007 05:09:01 +0000 (05:09 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Thu, 5 Jul 2007 05:09:01 +0000 (05:09 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@29 7c3ca157-0c34-0410-bff1-cbf682f78f5c

functions.inc.php
indexes.inc.php
table.inc.php

index 6c5cf0883ce93965a63fd08eca681171d8d3198d..dba5cdb7c9ed723d8dd3d6871401d9bf8e2c551f 100644 (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)) {
index 6f96806ad7d63578af59878d1dd2df00e30922a1..f43f8bb087749e566529c343bd3d4adf8d6a9317 100644 (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>";
        }
index b29ffb7c07450a92fb710aab17b871f03e2bfee8..b560d57e79bec596ad0b7a2a2d28a9378036b1ea 100644 (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";