Warn about selecting data without index
This commit is contained in:
parent
b0666e537d
commit
739bcb0979
|
@ -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";
|
||||
}
|
||||
|
||||
|
|
|
@ -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ů'),
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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"];
|
||||
|
|
|
@ -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 ? '' : '!'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ Adminer 3.4.0-dev:
|
|||
Print current time next to executed SQL queries
|
||||
Highlight code in SQL command by CodeMirror
|
||||
Link to descending order
|
||||
Warn about selecting data without index
|
||||
Allow specifying database in login form
|
||||
Link to original table in EXPLAIN of SELECT * FROM table t
|
||||
MySQL: inform about disabled event_scheduler
|
||||
|
|
|
@ -271,7 +271,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
|
|||
function selectLengthPrint($text_length) {
|
||||
}
|
||||
|
||||
function selectActionPrint() {
|
||||
function selectActionPrint($indexes) {
|
||||
echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
|
||||
echo "<input type='submit' value='" . lang('Select') . "'>";
|
||||
echo "</div></fieldset>\n";
|
||||
|
|
Loading…
Reference in a new issue