diff --git a/functions.inc.php b/functions.inc.php index 8d7ad515..0c39d3f6 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -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(); } diff --git a/indexes.inc.php b/indexes.inc.php index 5f604cd6..1f402194 100644 --- a/indexes.inc.php +++ b/indexes.inc.php @@ -1,31 +1,35 @@ $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 "
" . lang('Unable to operate indexes') . ": " . htmlspecialchars($error) . "
\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 => "")); } ?>