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

Warn about selecting data without index

This commit is contained in:
Jakub Vrana
2012-05-16 23:54:56 -07:00
parent b0666e537d
commit 739bcb0979
7 changed files with 76 additions and 17 deletions

View File

@@ -233,23 +233,22 @@ username.form['auth[driver]'].onchange();
foreach ($indexes as $i => $index) {
if ($index["type"] == "FULLTEXT") {
echo "(<i>" . implode("</i>, <i>", array_map('h', $index["columns"])) . "</i>) AGAINST";
echo " <input name='fulltext[$i]' value='" . h($_GET["fulltext"][$i]) . "'>";
echo " <input name='fulltext[$i]' value='" . h($_GET["fulltext"][$i]) . "' onchange='selectFieldChange(this.form);'>";
echo checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL");
echo "<br>\n";
}
}
$i = 0;
foreach ((array) $_GET["where"] as $val) {
if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
echo "<div><select name='where[$i][col]'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, $val["col"], true) . "</select>";
echo html_select("where[$i][op]", $this->operators, $val["op"]);
echo "<input name='where[$i][val]' value='" . h($val["val"]) . "'></div>\n";
$i++;
$_GET["where"] = (array) $_GET["where"];
reset($_GET["where"]);
$change_next = "this.nextSibling.onchange();";
for ($i = 0; $i <= count($_GET["where"]); $i++) {
list(, $val) = each($_GET["where"]);
if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators))) {
echo "<div><select name='where[$i][col]' onchange='$change_next'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, $val["col"], true) . "</select>";
echo html_select("where[$i][op]", $this->operators, $val["op"], $change_next);
echo "<input name='where[$i][val]' value='" . h($val["val"]) . "' onchange='" . ($val ? "selectFieldChange(this.form)" : "selectAddRow(this)") . ";'></div>\n";
}
}
echo "<div><select name='where[$i][col]' onchange='this.nextSibling.nextSibling.onchange();'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, null, true) . "</select>";
echo html_select("where[$i][op]", $this->operators, "=");
echo "<input name='where[$i][val]' onchange='selectAddRow(this);'></div>\n";
echo "</div></fieldset>\n";
}
@@ -264,7 +263,7 @@ username.form['auth[driver]'].onchange();
$i = 0;
foreach ((array) $_GET["order"] as $key => $val) {
if (isset($columns[$val])) {
echo "<div><select name='order[$i]'><option>" . optionlist($columns, $val, true) . "</select>";
echo "<div><select name='order[$i]' onchange='selectFieldChange(this.form);'><option>" . optionlist($columns, $val, true) . "</select>";
echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')) . "</div>\n";
$i++;
}
@@ -297,11 +296,28 @@ username.form['auth[driver]'].onchange();
}
/** Print action box in select
* @param array
* @return null
*/
function selectActionPrint() {
function selectActionPrint($indexes) {
echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
echo "<input type='submit' value='" . lang('Select') . "'>";
echo " <span id='noindex' title='" . lang('Full table scan') . "'></span>";
echo "<script type='text/javascript'>\n";
echo "var indexColumns = ";
$columns = array();
foreach ($indexes as $index) {
if ($index["type"] != "FULLTEXT") {
$columns[reset($index["columns"])] = 1;
}
}
$columns[""] = 1;
foreach ($columns as $key => $val) {
json_row($key);
}
echo ";\n";
echo "selectFieldChange(document.getElementById('form'));\n";
echo "</script>\n";
echo "</div></fieldset>\n";
}

View File

@@ -227,6 +227,7 @@ $translations = array(
'Limit' => 'Limit',
'Text length' => 'Délka textů',
'Action' => 'Akce',
'Full table scan' => 'Průchod celé tabulky',
'Unable to select the table' => 'Nepodařilo se vypsat tabulku',
'No rows.' => 'Žádné řádky.',
'%d row(s)' => array('%d řádek', '%d řádky', '%d řádků'),

View File

@@ -227,6 +227,7 @@ $translations = array(
'Limit' => 'xx',
'Text length' => 'xx',
'Action' => 'xx',
'Full table scan' => 'xx',
'Unable to select the table' => 'xx',
'No rows.' => 'xx',
'%d row(s)' => array('xx', 'xx'),

View File

@@ -209,7 +209,7 @@ if (!$columns) {
$adminer->selectOrderPrint($order, $columns, $indexes);
$adminer->selectLimitPrint($limit);
$adminer->selectLengthPrint($text_length);
$adminer->selectActionPrint();
$adminer->selectActionPrint($indexes);
echo "</form>\n";
$page = $_GET["page"];

View File

@@ -167,7 +167,10 @@ function pageClick(href, page, event) {
* @param HTMLSelectElement
*/
function selectAddRow(field) {
field.onchange = function () { };
field.onchange = function () {
selectFieldChange(field.form);
};
field.onchange();
var row = field.parentNode.cloneNode(true);
var selects = row.getElementsByTagName('select');
for (var i=0; i < selects.length; i++) {
@@ -183,7 +186,44 @@ function selectAddRow(field) {
field.parentNode.parentNode.appendChild(row);
}
/** Check whether the query will be executed with index
* @param HTMLFormElement
*/
function selectFieldChange(form) {
var ok = (function () {
var inputs = form.getElementsByTagName('input');
for (var i=0; i < inputs.length; i++) {
var input = inputs[i];
if (/^fulltext/.test(input.name) && input.value) {
return true;
}
}
var ok = true;
var selects = form.getElementsByTagName('select');
for (var i=0; i < selects.length; i++) {
var select = selects[i];
var col = selectValue(select);
var match = /^(where.+)col\]/.exec(select.name);
if (match) {
var op = selectValue(form[match[1] + 'op]']);
var val = form[match[1] + 'val]'].value;
if (col in indexColumns && (!/LIKE|REGEXP/.test(op) || (op == 'LIKE' && val.charAt(0) != '%'))) {
return true;
} else if (col || val) {
ok = false;
}
}
if (col && /^order/.test(select.name)) {
if (!(col in indexColumns)) {
ok = false;
}
break;
}
}
return ok;
})();
setHtml('noindex', (ok ? '' : '!'));
}