Skip to content

Commit

Permalink
Compliance with ONLY_FULL_GROUP_BY sql_mode
Browse files Browse the repository at this point in the history
The SQL query retrieving rankings from the database was modified so it
is no longer necessary to set sql_mode, which requires SUPER privileges.

All columns referenced in the SELECT statement were added to the
GROUP BY clause.

Fixes #10
  • Loading branch information
dregad committed Sep 8, 2019
1 parent 8ac1c1c commit a70520c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 3 additions & 5 deletions pages/issue_ranking.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
} else {
$where_clause .= " AND {$skipThese1} AND {$skipThese2} " ;
}
// fetch collected data from DB
$dbquery= "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))";
$dboutput = db_query($dbquery);

//// fetch collected data from DB
$plugin_table = plugin_table("support_data");
$bug_table = db_get_table('bug');
$dbquery = "SELECT
Expand All @@ -43,12 +40,13 @@
LEFT OUTER JOIN (SELECT bugid, count(rating) as b2_count, sum(rating) as b2_sum FROM {$plugin_table} GROUP BY bugid, rating HAVING rating = 2) b2 ON sd.bugid = b2.bugid
LEFT OUTER JOIN (SELECT bugid, count(rating) as b1_count, sum(rating) as b1_sum FROM {$plugin_table} GROUP BY bugid, rating HAVING rating = 1) b1 ON sd.bugid = b1.bugid
{$where_clause}
GROUP BY sd.bugid
GROUP BY sd.bugid, bm2_count, bm2_sum, bm1_count, bm1_sum, b2_count, b2_sum, b1_count, b1_sum
ORDER BY sum(sd.rating) DESC ";
// echo "<p>$dbquery</p>";
//die();
$dboutput = db_query($dbquery);


$resultset = array();
// load listable issues into array
while($row = db_fetch_array($dboutput)) {
Expand Down
4 changes: 1 addition & 3 deletions pages/issue_ranking_xls.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
}

// fetch collected data from DB
$dbquery= "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))";
$dboutput = db_query($dbquery);
$plugin_table = plugin_table("support_data","GaugeSupport");
$bug_table = db_get_table('mantis_bug_table');
$dbquery = "SELECT
Expand All @@ -54,7 +52,7 @@
LEFT OUTER JOIN (SELECT bugid, count(rating) as b2_count, sum(rating) as b2_sum FROM {$plugin_table} GROUP BY bugid, rating HAVING rating = 2) b2 ON sd.bugid = b2.bugid
LEFT OUTER JOIN (SELECT bugid, count(rating) as b1_count, sum(rating) as b1_sum FROM {$plugin_table} GROUP BY bugid, rating HAVING rating = 1) b1 ON sd.bugid = b1.bugid
{$where_clause}
GROUP BY sd.bugid
GROUP BY sd.bugid, bm2_count, bm2_sum, bm1_count, bm1_sum, b2_count, b2_sum, b1_count, b1_sum
ORDER BY sum(sd.rating) DESC ";
// echo "<p>$dbquery</p>";
//die();
Expand Down

0 comments on commit a70520c

Please sign in to comment.