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 => "")); } ?>
+\n"; - $j++; + echo "\n"; + $j++; } //! JavaScript for adding more indexes and columns ?> -
"; - ksort($index["columns"]); - foreach ($index["columns"] as $i => $column) { - if (strlen($column)) { - echo ""; - } - } - echo ""; - //! indexes from substring - echo "
"; + ksort($index["columns"]); + foreach ($index["columns"] as $i => $column) { + echo ""; + echo "\n"; } + echo "

diff --git a/table.inc.php b/table.inc.php index e2301d4e..7b576414 100644 --- a/table.inc.php +++ b/table.inc.php @@ -28,7 +28,11 @@ if (!$result) { echo "\n"; foreach ($indexes as $index) { ksort($index["columns"]); - echo "\n"; + $print = array(); + foreach ($index["columns"] as $key => $val) { + $print[] = "" . htmlspecialchars($val) . "" . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : ""); + } + echo "\n"; } echo "
$index[type]" . implode(", ", $index["columns"]) . "
$index[type]" . implode(", ", $print) . "
\n"; } @@ -41,9 +45,10 @@ if (!$result) { echo "\n"; foreach ($foreign_keys as $name => $foreign_key) { echo ""; - echo ""; + echo ""; $link = (strlen($foreign_key["db"]) ? "" . htmlspecialchars($foreign_key["db"]) . "." : "") . htmlspecialchars($foreign_key["table"]); - echo '"; + echo '"; echo ''; echo "\n"; }
" . implode(", ", $foreign_key["source"]) . "" . implode(", ", array_map('htmlspecialchars', $foreign_key["source"])) . "$link(" . implode(", ", $foreign_key["target"]) . ")$link"; + echo "(" . implode(", ", array_map('htmlspecialchars', $foreign_key["target"])) . ")' . (!strlen($foreign_key["db"]) ? '' . lang('Alter') . '' : ' ') . '