1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-11 09:04:02 +02:00

Editable index names

This commit is contained in:
Jakub Vrana
2011-07-13 15:13:00 +02:00
parent ead05e6839
commit ac8a64e88a
7 changed files with 59 additions and 23 deletions

View File

@@ -13,6 +13,7 @@ if ($jush == "sqlite") { // doesn't support primary key
if ($_POST && !$error && !$_POST["add"]) {
$alter = array();
foreach ($_POST["indexes"] as $index) {
$name = $index["name"];
if (in_array($index["type"], $index_types)) {
$columns = array();
$lengths = array();
@@ -27,22 +28,23 @@ if ($_POST && !$error && !$_POST["add"]) {
}
}
if ($columns) {
foreach ($indexes as $name => $existing) {
$existing = $indexes[$name];
if ($existing) {
ksort($existing["columns"]);
ksort($existing["lengths"]);
if ($index["type"] == $existing["type"] && array_values($existing["columns"]) === $columns && (!$existing["lengths"] || array_values($existing["lengths"]) === $lengths)) {
// skip existing index
unset($indexes[$name]);
continue 2;
continue;
}
}
$alter[] = array($index["type"], "(" . implode(", ", $set) . ")");
$alter[] = array($index["type"], $name, "(" . implode(", ", $set) . ")");
}
}
}
// drop removed indexes
foreach ($indexes as $name => $existing) {
$alter[] = array($existing["type"], idf_escape($name), "DROP");
$alter[] = array($existing["type"], $name, "DROP");
}
if (!$alter) {
redirect(ME . "table=" . urlencode($TABLE));
@@ -69,6 +71,7 @@ if ($_POST) {
}
} else {
foreach ($row["indexes"] as $key => $index) {
$row["indexes"][$key]["name"] = $key;
$row["indexes"][$key]["columns"][] = "";
}
$row["indexes"][] = array("columns" => array(1 => ""));
@@ -77,7 +80,7 @@ if ($_POST) {
<form action="" method="post">
<table cellspacing="0" class="nowrap">
<thead><tr><th><?php echo lang('Index Type'); ?><th><?php echo lang('Column (length)'); ?></thead>
<thead><tr><th><?php echo lang('Index Type'); ?><th><?php echo lang('Column (length)'); ?><th><?php echo lang('Name'); ?></thead>
<?php
$j = 1;
foreach ($row["indexes"] as $index) {
@@ -85,10 +88,11 @@ foreach ($row["indexes"] as $index) {
ksort($index["columns"]);
$i = 1;
foreach ($index["columns"] as $key => $column) {
echo "<span>" . html_select("indexes[$j][columns][$i]", array(-1 => "") + $fields, $column, ($i == count($index["columns"]) ? "indexesAddColumn(this);" : 1));
echo "<span>" . html_select("indexes[$j][columns][$i]", array(-1 => "") + $fields, $column, ($i == count($index["columns"]) ? "indexesAddColumn" : "indexesChangeColumn") . "(this, '" . js_escape($jush == "sql" ? "" : $_GET["indexes"] . "_") . "');");
echo "<input name='indexes[$j][lengths][$i]' size='2' value='" . h($index["lengths"][$key]) . "'> </span>"; //! hide for non-MySQL drivers, add ASC|DESC
$i++;
}
echo "<td><input name='indexes[$j][name]' value='" . h($index["name"]) . "'>\n";
$j++;
}
?>