]> git.joonet.de Git - adminer.git/commitdiff
Index length
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Sat, 14 Jul 2007 07:06:53 +0000 (07:06 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Sat, 14 Jul 2007 07:06:53 +0000 (07:06 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@166 7c3ca157-0c34-0410-bff1-cbf682f78f5c

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

index 8d7ad515d08dd541fe9281c66af2ec81b76c1b5a..0c39d3f67d79b0e69bdd216643cde0078d54c28c 100644 (file)
@@ -79,6 +79,7 @@ function indexes($table) {
                while ($row = $result->fetch_assoc()) {
                        $return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
                        $return[$row["Key_name"]]["columns"][$row["Seq_in_index"]] = $row["Column_name"];
+                       $return[$row["Key_name"]]["lengths"][$row["Seq_in_index"]] = $row["Sub_part"];
                }
                $result->free();
        }
index 5f604cd6d67a480a78cd404d8080033c0dacf3ad..1f40219466a59e17edf1c923656fe4ecd2a0ae43 100644 (file)
@@ -1,31 +1,35 @@
 <?php
 $index_types = array("PRIMARY", "UNIQUE", "INDEX", "FULLTEXT");
 $indexes = indexes($_GET["indexes"]);
-$fields = array_keys(fields($_GET["indexes"]));
 if ($_POST && !$error && !$_POST["add"]) {
        $alter = array();
        foreach ($_POST["indexes"] as $index) {
                if (in_array($index["type"], $index_types)) {
                        $columns = array();
+                       $lengths = array();
+                       $set = array();
                        ksort($index["columns"]);
-                       foreach ($index["columns"] as $column) {
-                               if (in_array($column, $fields, true)) {
+                       foreach ($index["columns"] as $key => $column) {
+                               if (strlen($column)) {
+                                       $length = $index["lengths"][$key];
+                                       $set[] = idf_escape($column) . ($length ? "(" . intval($length) . ")" : "");
                                        $columns[count($columns) + 1] = $column;
+                                       $lengths[count($lengths) + 1] = ($length ? $length : null);
                                }
                        }
                        if ($columns) {
                                foreach ($indexes as $name => $existing) {
-                                       if ($index["type"] == $existing["type"] && $existing["columns"] == $columns) {
+                                       if ($index["type"] == $existing["type"] && $existing["columns"] === $columns && $existing["lengths"] === $lengths) {
                                                unset($indexes[$name]);
                                                continue 2;
                                        }
                                }
-                               $alter[] = "ADD $index[type]" . ($index["type"] == "PRIMARY" ? " KEY" : "") . " (" . implode(", ", array_map('idf_escape', $columns)) . ")";
+                               $alter[] = "ADD $index[type]" . ($index["type"] == "PRIMARY" ? " KEY" : "") . " (" . implode(", ", $set) . ")";
                        }
                }
        }
        foreach ($indexes as $name => $existing) {
-               $alter[] = "DROP INDEX " . idf_escape($name);
+               $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));
@@ -34,38 +38,48 @@ if ($_POST && !$error && !$_POST["add"]) {
 }
 page_header(lang('Indexes') . ': ' . htmlspecialchars($_GET["indexes"]));
 
+$fields = array_keys(fields($_GET["indexes"]));
 if ($_POST) {
+       $row = $_POST;
        if (!$_POST["add"]) {
                echo "<p class='error'>" . lang('Unable to operate indexes') . ": " . htmlspecialchars($error) . "</p>\n";
+       } else {
+               foreach ($row["indexes"] as $key => $index) {
+                       if (strlen($index["columns"][count($index["columns"])])) {
+                               $row["indexes"][$key]["columns"][] = "";
+                       }
+               }
+               $index = $row["indexes"][count($row["indexes"]) - 1];
+               if ($index["type"] || array_filter($index["columns"], 'strlen') || array_filter($index["columns"], 'length')) {
+                       $row["indexes"][] = array("columns" => array(1 => ""));
+               }
        }
-       $row = $_POST;
 } else {
        $row = array("indexes" => $indexes);
+       foreach ($row["indexes"] as $key => $index) {
+               $row["indexes"][$key]["columns"][] = "";
+       }
+       $row["indexes"][] = array("columns" => array(1 => ""));
 }
 ?>
 
 <form action="" method="post">
 <table border="0" cellspacing="0" cellpadding="2">
+<thead><tr><th><?php echo lang('Index Type'); ?></th><td><?php echo lang('Column (length)'); ?></td></tr></thead>
 <?php
 $j = 0;
 foreach ($row["indexes"] as $index) {
-       if ($index["type"] || array_filter($index["columns"], 'strlen')) {
-               echo "<tr><td><select name='indexes[$j][type]'><option></option>" . optionlist($index_types, $index["type"]) . "</select></td><td>";
-               ksort($index["columns"]);
-               foreach ($index["columns"] as $i => $column) {
-                       if (strlen($column)) {
-                               echo "<select name='indexes[$j][columns][$i]'><option></option>" . optionlist($fields, $column) . "</select>";
-                       }
-               }
-               echo "<select name='indexes[$j][columns][" . ($i+1) . "]'><option></option>" . optionlist($fields, array()) . "</select>";
-               //! indexes from substring
-               echo "</td></tr>\n";
-               $j++;
+       echo "<tr><td><select name='indexes[$j][type]'><option></option>" . optionlist($index_types, $index["type"]) . "</select></td><td>";
+       ksort($index["columns"]);
+       foreach ($index["columns"] as $i => $column) {
+               echo "<select name='indexes[$j][columns][$i]'><option></option>" . optionlist($fields, $column) . "</select>";
+               echo "<input name='indexes[$j][lengths][$i]' size='2' value=\"" . htmlspecialchars($index["lengths"][$i]) . "\" />\n";
        }
+       echo "</td></tr>\n";
+       $j++;
 }
 //! JavaScript for adding more indexes and columns
 ?>
-<tr><td><select name="indexes[<?php echo $j; ?>][type]"><option></option><?php echo optionlist($index_types, array()); ?></select></td><td><select name="indexes[<?php echo $j; ?>][columns][1]"><option></option><?php echo optionlist($fields, array()); ?></select></td></tr>
 </table>
 <p>
 <input type="hidden" name="token" value="<?php echo $token; ?>" />
index e2301d4e8b4e1bcb28d1844ccbc90485b5c76060..7b576414f87a8cdf3717091f9a214588153bd601 100644 (file)
@@ -28,7 +28,11 @@ if (!$result) {
                echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
                foreach ($indexes as $index) {
                        ksort($index["columns"]);
-                       echo "<tr><td>$index[type]</td><td><i>" . implode("</i>, <i>", $index["columns"]) . "</i></td></tr>\n";
+                       $print = array();
+                       foreach ($index["columns"] as $key => $val) {
+                               $print[] = "<i>" . htmlspecialchars($val) . "</i>" . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "");
+                       }
+                       echo "<tr><td>$index[type]</td><td>" . implode(", ", $print) . "</td></tr>\n";
                }
                echo "</table>\n";
        }
@@ -41,9 +45,10 @@ if (!$result) {
                        echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
                        foreach ($foreign_keys as $name => $foreign_key) {
                                echo "<tr>";
-                               echo "<td><i>" . implode("</i>, <i>", $foreign_key["source"]) . "</i></td>";
+                               echo "<td><i>" . implode("</i>, <i>", array_map('htmlspecialchars', $foreign_key["source"])) . "</i></td>";
                                $link = (strlen($foreign_key["db"]) ? "<strong>" . htmlspecialchars($foreign_key["db"]) . "</strong>." : "") . htmlspecialchars($foreign_key["table"]);
-                               echo '<td><a href="' . htmlspecialchars(strlen($foreign_key["db"]) ? preg_replace('~db=[^&]*~', "db=" . urlencode($foreign_key["db"]), $SELF) : $SELF) . "table=" . urlencode($foreign_key["table"]) . "\">$link</a>(<em>" . implode("</em>, <em>", $foreign_key["target"]) . "</em>)</td>";
+                               echo '<td><a href="' . htmlspecialchars(strlen($foreign_key["db"]) ? preg_replace('~db=[^&]*~', "db=" . urlencode($foreign_key["db"]), $SELF) : $SELF) . "table=" . urlencode($foreign_key["table"]) . "\">$link</a>";
+                               echo "(<em>" . implode("</em>, <em>", array_map('htmlspecialchars', $foreign_key["target"])) . "</em>)</td>";
                                echo '<td>' . (!strlen($foreign_key["db"]) ? '<a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '&amp;name=' . urlencode($name) . '">' . lang('Alter') . '</a>' : '&nbsp;') . '</td>';
                                echo "</tr>\n";
                        }