Editable index names
This commit is contained in:
parent
ead05e6839
commit
ac8a64e88a
|
@ -436,16 +436,16 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
|
||||||
$index = array();
|
$index = array();
|
||||||
$drop = array();
|
$drop = array();
|
||||||
foreach ($alter as $val) {
|
foreach ($alter as $val) {
|
||||||
if ($val[2]) {
|
if ($val[2] == "DROP") {
|
||||||
if ($val[0] == "PRIMARY") { //! sometimes used also for UNIQUE
|
if ($val[0] == "PRIMARY") { //! sometimes used also for UNIQUE
|
||||||
$drop[] = $val[1];
|
$drop[] = idf_escape($val[1]);
|
||||||
} else {
|
} else {
|
||||||
$index[] = "$val[1] ON " . table($table);
|
$index[] = idf_escape($val[1]) . " ON " . table($table);
|
||||||
}
|
}
|
||||||
} elseif (!queries(($val[0] != "PRIMARY"
|
} elseif (!queries(($val[0] != "PRIMARY"
|
||||||
? "CREATE" . ($val[0] != "INDEX" ? " UNIQUE" : "") . " INDEX " . idf_escape(uniqid($table . "_")) . " ON " . table($table)
|
? "CREATE $val[0] " . ($val[0] != "INDEX" ? "INDEX " : "") . idf_escape($val[1] != "" ? $val[1] : uniqid($table . "_")) . " ON " . table($table)
|
||||||
: "ALTER TABLE " . table($table) . " ADD PRIMARY KEY"
|
: "ALTER TABLE " . table($table) . " ADD PRIMARY KEY"
|
||||||
) . " $val[1]")) {
|
) . " $val[2]")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -611,12 +611,15 @@ if (!defined("DRIVER")) {
|
||||||
|
|
||||||
/** Run commands to alter indexes
|
/** Run commands to alter indexes
|
||||||
* @param string escaped table name
|
* @param string escaped table name
|
||||||
* @param array of array("index type", "(columns definition)") or array("index type", "escaped name", "DROP")
|
* @param array of array("index type", "name", "(columns definition)") or array("index type", "name", "DROP")
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function alter_indexes($table, $alter) {
|
function alter_indexes($table, $alter) {
|
||||||
foreach ($alter as $key => $val) {
|
foreach ($alter as $key => $val) {
|
||||||
$alter[$key] = ($val[2] ? "\nDROP INDEX " : "\nADD $val[0] " . ($val[0] == "PRIMARY" ? "KEY " : "")) . $val[1];
|
$alter[$key] = ($val[2] == "DROP"
|
||||||
|
? "\nDROP INDEX " . idf_escape($val[1])
|
||||||
|
: "\nADD $val[0] " . ($val[0] == "PRIMARY" ? "KEY " : "") . ($val[1] != "" ? idf_escape($val[1]) . " " : "") . $val[2]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return queries("ALTER TABLE " . table($table) . implode(",", $alter));
|
return queries("ALTER TABLE " . table($table) . implode(",", $alter));
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,10 +383,13 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.constraint_schema = current_sche
|
||||||
$drop = array();
|
$drop = array();
|
||||||
foreach ($alter as $val) {
|
foreach ($alter as $val) {
|
||||||
if ($val[0] != "INDEX") {
|
if ($val[0] != "INDEX") {
|
||||||
$create[] = ($val[2] ? "\nDROP CONSTRAINT " : "\nADD $val[0] " . ($val[0] == "PRIMARY" ? "KEY " : "")) . $val[1];
|
$create[] = ($val[2] == "DROP"
|
||||||
} elseif ($val[2]) {
|
? "\nDROP CONSTRAINT " . idf_escape($val[1])
|
||||||
$drop[] = $val[1];
|
: "\nADD $val[0] " . ($val[0] == "PRIMARY" ? "KEY " : "") . $val[2]
|
||||||
} elseif (!queries("CREATE INDEX " . idf_escape(uniqid($table . "_")) . " ON " . table($table) . " $val[1]")) {
|
);
|
||||||
|
} elseif ($val[2] == "DROP") {
|
||||||
|
$drop[] = idf_escape($val[1]);
|
||||||
|
} elseif (!queries("CREATE INDEX " . idf_escape($val[1] != "" ? $val[1] : uniqid($table . "_")) . " ON " . table($table) . " $val[2]")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,7 +422,10 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
|
|
||||||
function alter_indexes($table, $alter) {
|
function alter_indexes($table, $alter) {
|
||||||
foreach ($alter as $val) {
|
foreach ($alter as $val) {
|
||||||
if (!queries(($val[2] ? "DROP INDEX" : "CREATE" . ($val[0] != "INDEX" ? " UNIQUE" : "") . " INDEX " . idf_escape(uniqid($table . "_")) . " ON " . table($table)) . " $val[1]")) {
|
if (!queries($val[2] == "DROP"
|
||||||
|
? "DROP INDEX " . idf_escape($val[1])
|
||||||
|
: "CREATE $val[0] " . ($val[0] != "INDEX" ? "INDEX " : "") . idf_escape($val[1] != "" ? $val[1] : uniqid($table . "_")) . " ON " . table($table) . " $val[2]"
|
||||||
|
)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ if ($jush == "sqlite") { // doesn't support primary key
|
||||||
if ($_POST && !$error && !$_POST["add"]) {
|
if ($_POST && !$error && !$_POST["add"]) {
|
||||||
$alter = array();
|
$alter = array();
|
||||||
foreach ($_POST["indexes"] as $index) {
|
foreach ($_POST["indexes"] as $index) {
|
||||||
|
$name = $index["name"];
|
||||||
if (in_array($index["type"], $index_types)) {
|
if (in_array($index["type"], $index_types)) {
|
||||||
$columns = array();
|
$columns = array();
|
||||||
$lengths = array();
|
$lengths = array();
|
||||||
|
@ -27,22 +28,23 @@ if ($_POST && !$error && !$_POST["add"]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($columns) {
|
if ($columns) {
|
||||||
foreach ($indexes as $name => $existing) {
|
$existing = $indexes[$name];
|
||||||
|
if ($existing) {
|
||||||
ksort($existing["columns"]);
|
ksort($existing["columns"]);
|
||||||
ksort($existing["lengths"]);
|
ksort($existing["lengths"]);
|
||||||
if ($index["type"] == $existing["type"] && array_values($existing["columns"]) === $columns && (!$existing["lengths"] || array_values($existing["lengths"]) === $lengths)) {
|
if ($index["type"] == $existing["type"] && array_values($existing["columns"]) === $columns && (!$existing["lengths"] || array_values($existing["lengths"]) === $lengths)) {
|
||||||
// skip existing index
|
// skip existing index
|
||||||
unset($indexes[$name]);
|
unset($indexes[$name]);
|
||||||
continue 2;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$alter[] = array($index["type"], "(" . implode(", ", $set) . ")");
|
$alter[] = array($index["type"], $name, "(" . implode(", ", $set) . ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// drop removed indexes
|
// drop removed indexes
|
||||||
foreach ($indexes as $name => $existing) {
|
foreach ($indexes as $name => $existing) {
|
||||||
$alter[] = array($existing["type"], idf_escape($name), "DROP");
|
$alter[] = array($existing["type"], $name, "DROP");
|
||||||
}
|
}
|
||||||
if (!$alter) {
|
if (!$alter) {
|
||||||
redirect(ME . "table=" . urlencode($TABLE));
|
redirect(ME . "table=" . urlencode($TABLE));
|
||||||
|
@ -69,6 +71,7 @@ if ($_POST) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($row["indexes"] as $key => $index) {
|
foreach ($row["indexes"] as $key => $index) {
|
||||||
|
$row["indexes"][$key]["name"] = $key;
|
||||||
$row["indexes"][$key]["columns"][] = "";
|
$row["indexes"][$key]["columns"][] = "";
|
||||||
}
|
}
|
||||||
$row["indexes"][] = array("columns" => array(1 => ""));
|
$row["indexes"][] = array("columns" => array(1 => ""));
|
||||||
|
@ -77,7 +80,7 @@ if ($_POST) {
|
||||||
|
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<table cellspacing="0" class="nowrap">
|
<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
|
<?php
|
||||||
$j = 1;
|
$j = 1;
|
||||||
foreach ($row["indexes"] as $index) {
|
foreach ($row["indexes"] as $index) {
|
||||||
|
@ -85,10 +88,11 @@ foreach ($row["indexes"] as $index) {
|
||||||
ksort($index["columns"]);
|
ksort($index["columns"]);
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach ($index["columns"] as $key => $column) {
|
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
|
echo "<input name='indexes[$j][lengths][$i]' size='2' value='" . h($index["lengths"][$key]) . "'> </span>"; //! hide for non-MySQL drivers, add ASC|DESC
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
echo "<td><input name='indexes[$j][name]' value='" . h($index["name"]) . "'>\n";
|
||||||
$j++;
|
$j++;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -343,17 +343,38 @@ function indexesAddRow(field) {
|
||||||
selects[i].name = selects[i].name.replace(/indexes\[\d+/, '$&1');
|
selects[i].name = selects[i].name.replace(/indexes\[\d+/, '$&1');
|
||||||
selects[i].selectedIndex = 0;
|
selects[i].selectedIndex = 0;
|
||||||
}
|
}
|
||||||
var input = row.getElementsByTagName('input')[0];
|
var inputs = row.getElementsByTagName('input');
|
||||||
input.name = input.name.replace(/indexes\[\d+/, '$&1');
|
for (var i=0; i < inputs.length; i++) {
|
||||||
input.value = '';
|
inputs[i].name = inputs[i].name.replace(/indexes\[\d+/, '$&1');
|
||||||
|
inputs[i].value = '';
|
||||||
|
}
|
||||||
parent.parentNode.appendChild(row);
|
parent.parentNode.appendChild(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Change column in index
|
||||||
|
* @param HTMLSelectElement
|
||||||
|
* @param string name prefix
|
||||||
|
*/
|
||||||
|
function indexesChangeColumn(field, prefix) {
|
||||||
|
var columns = field.parentNode.parentNode.getElementsByTagName('select');
|
||||||
|
var names = [];
|
||||||
|
for (var i=0; i < columns.length; i++) {
|
||||||
|
var value = selectValue(columns[i]);
|
||||||
|
if (value) {
|
||||||
|
names.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
field.form[field.name.replace(/\].*/, '][name]')].value = prefix + names.join('_');
|
||||||
|
}
|
||||||
|
|
||||||
/** Add column for index
|
/** Add column for index
|
||||||
* @param HTMLSelectElement
|
* @param HTMLSelectElement
|
||||||
|
* @param string name prefix
|
||||||
*/
|
*/
|
||||||
function indexesAddColumn(field) {
|
function indexesAddColumn(field, prefix) {
|
||||||
field.onchange = function () { };
|
field.onchange = function () {
|
||||||
|
indexesChangeColumn(field, prefix);
|
||||||
|
};
|
||||||
var select = field.form[field.name.replace(/\].*/, '][type]')];
|
var select = field.form[field.name.replace(/\].*/, '][type]')];
|
||||||
if (!select.selectedIndex) {
|
if (!select.selectedIndex) {
|
||||||
select.selectedIndex = 3;
|
select.selectedIndex = 3;
|
||||||
|
@ -367,6 +388,7 @@ function indexesAddColumn(field) {
|
||||||
input.name = input.name.replace(/\]\[\d+/, '$&1');
|
input.name = input.name.replace(/\]\[\d+/, '$&1');
|
||||||
input.value = '';
|
input.value = '';
|
||||||
field.parentNode.parentNode.appendChild(column);
|
field.parentNode.parentNode.appendChild(column);
|
||||||
|
field.onchange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
Adminer 3.3.0-dev:
|
Adminer 3.3.0-dev:
|
||||||
Use Esc to disable in-place edit
|
Use Esc to disable in-place edit
|
||||||
Shortcut for database privileges
|
Shortcut for database privileges
|
||||||
|
Editable index names
|
||||||
Append new index with auto index selection (bug #3282127)
|
Append new index with auto index selection (bug #3282127)
|
||||||
Preserve original timestamp value in multiple update (bug #3312614)
|
Preserve original timestamp value in multiple update (bug #3312614)
|
||||||
Bit type default value
|
Bit type default value
|
||||||
|
|
Loading…
Reference in a new issue