Skip to content
Browse files

Warn about grouping data without index

  • Loading branch information...
1 parent 07e2c3b commit 55831095b6cb56443e4e170e2032017b09da4dd4 @vrana committed Jul 29, 2012
Showing with 19 additions and 2 deletions.
  1. +1 −1 adminer/include/adminer.inc.php
  2. +18 −1 adminer/static/functions.js
View
2 adminer/include/adminer.inc.php
@@ -214,7 +214,7 @@ function selectColumnsPrint($select, $columns) {
foreach ($select as $key => $val) {
$val = $_GET["columns"][$key];
echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, $val["fun"]);
- echo "(<select name='columns[$i][col]'><option>" . optionlist($columns, $val["col"], true) . "</select>)</div>\n";
+ echo "(<select name='columns[$i][col]' onchange='selectFieldChange(this.form);'><option>" . optionlist($columns, $val["col"], true) . "</select>)</div>\n";
$i++;
}
echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, "", "this.nextSibling.nextSibling.onchange();");
View
19 adminer/static/functions.js
@@ -233,6 +233,8 @@ function selectFieldChange(form) {
}
var ok = true;
var selects = form.getElementsByTagName('select');
+ var group = false;
+ var columns = {};
for (var i=0; i < selects.length; i++) {
var select = selects[i];
var col = selectValue(select);
@@ -246,14 +248,29 @@ function selectFieldChange(form) {
ok = false;
}
}
- //! take grouping in select into account
+ if ((match = /^(columns.+)fun\]/.exec(select.name))) {
+ if (/^(avg|count|count distinct|group_concat|max|min|sum)$/.test(col)) {
+ group = true;
+ }
+ var val = selectValue(form[match[1] + 'col]']);
+ if (val) {
+ columns[col && col != 'count' ? '' : val] = 1;
+ }
+ }
if (col && /^order/.test(select.name)) {
if (!(col in indexColumns)) {
ok = false;
}
break;
}
}
+ if (group) {
+ for (var col in columns) {
+ if (!(col in indexColumns)) {
+ ok = false;
+ }
+ }
+ }
return ok;
})();
setHtml('noindex', (ok ? '' : '!'));

0 comments on commit 5583109

Please sign in to comment.
Something went wrong with that request. Please try again.