]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 286360: ANSI SQL does not allow aliases to be used in HAVING clause
authormkanat%kerio.com <>
Sat, 16 Apr 2005 07:37:23 +0000 (07:37 +0000)
committermkanat%kerio.com <>
Sat, 16 Apr 2005 07:37:23 +0000 (07:37 +0000)
Patch By Tomas Kopal <Tomas.Kopal@altap.cz> r=myk, r=joel, a=myk

Bugzilla/Search.pm
request.cgi

index 0283b7f763471c06389d01220ca0a36dd9746b49..bebbfd94a5377533410343c6eaf1336f4ac25b67 100644 (file)
@@ -600,8 +600,8 @@ sub init {
              # (see http://bugzilla.mozilla.org/show_bug.cgi?id=145588#c35).
              my $select_term =
                "(SUM($term1)/COUNT($term1) + $term2) AS relevance";
-\r
-             # add the column not used in aggregate function explicitly\r
+
+             # add the column not used in aggregate function explicitly
              push(@groupby, 'bugs.short_desc');
 
              # Users can specify to display the relevance field, in which case
@@ -726,10 +726,15 @@ sub init {
                  my $table = "longdescs_$chartid";
                  push(@supptables, "INNER JOIN longdescs AS $table " .
                                    "ON $table.bug_id = bugs.bug_id");
-                 my $field = "(100*((SUM($table.work_time)*COUNT(DISTINCT $table.bug_when)/COUNT(bugs.bug_id))/((SUM($table.work_time)*COUNT(DISTINCT $table.bug_when)/COUNT(bugs.bug_id))+bugs.remaining_time))) AS percentage_complete_$table";
-                 push(@fields, $field);
-                 push(@having, 
-                      "percentage_complete_$table $oper " . &::SqlQuote($v));
+                 my $expression = "(100 * ((SUM($table.work_time) *
+                                             COUNT(DISTINCT $table.bug_when) /
+                                             COUNT(bugs.bug_id)) /
+                                            ((SUM($table.work_time) *
+                                              COUNT(DISTINCT $table.bug_when) /
+                                              COUNT(bugs.bug_id)) +
+                                             bugs.remaining_time)))";
+                 push(@having, "$expression $oper " . &::SqlQuote($v));
+                 push(@groupby, "bugs.remaining_time");
              }
              $term = "0=0";
          },
@@ -814,9 +819,9 @@ sub init {
              # If the numbers are the same, all flags match the condition,
              # so this bug should be included.
              if ($t =~ m/not/) {
-                push(@fields, "SUM(CASE WHEN $ff IS NOT NULL THEN 1 ELSE 0 END) AS allflags_$chartid");
-                push(@fields, "SUM(CASE WHEN $term THEN 1 ELSE 0 END) AS matchingflags_$chartid");
-                push(@having, "allflags_$chartid = matchingflags_$chartid");
+                push(@having,
+                     "SUM(CASE WHEN $ff IS NOT NULL THEN 1 ELSE 0 END) = " .
+                     "SUM(CASE WHEN $term THEN 1 ELSE 0 END)");
                 $term = "0=0";
              }
          },
index 36f6c9ce7c2072aba97453bc0f844fc423dd4fdd..bc5eefa9acd83c962be955e8163f050fdb2972f7 100755 (executable)
@@ -76,50 +76,46 @@ sub queue {
                 flags.attach_id, attachments.description,
                 requesters.realname, requesters.login_name,
                 requestees.realname, requestees.login_name,
-    " . $dbh->sql_date_format('flags.creation_date', '%Y.%m.%d %H:%i') . ",
-    " . 
-    # Select columns that help us weed out secure bugs to which the user
-    # should not have access.
-    "            COUNT(DISTINCT ugmap.group_id) AS cntuseringroups, 
-                COUNT(DISTINCT bgmap.group_id) AS cntbugingroups, 
-                ((COUNT(DISTINCT ccmap.who) > 0 AND cclist_accessible = 1) 
-                  OR ((bugs.reporter = $::userid) AND bugs.reporter_accessible = 1) 
-                  OR bugs.assigned_to = $::userid ) AS canseeanyway 
-    " . 
+    " . $dbh->sql_date_format('flags.creation_date', '%Y.%m.%d %H:%i') .
     # Use the flags and flagtypes tables for information about the flags,
     # the bugs and attachments tables for target info, the profiles tables
     # for setter and requestee info, the products/components tables
     # so we can display product and component names, and the bug_group_map
-    # and user_group_map tables to help us weed out secure bugs to which
-    # the user should not have access.
-    " FROM      flags
-                LEFT JOIN attachments
+    # table to help us weed out secure bugs to which the user should not have
+    # access.
+    "
+      FROM           flags 
+           LEFT JOIN attachments
                   ON ($attach_join_clause)
-                INNER JOIN flagtypes
+          INNER JOIN flagtypes
                   ON flags.type_id = flagtypes.id
-                INNER JOIN profiles AS requesters
+          INNER JOIN profiles AS requesters
                   ON flags.setter_id = requesters.userid
-                LEFT JOIN profiles AS requestees
+           LEFT JOIN profiles AS requestees
                   ON flags.requestee_id  = requestees.userid
-                INNER JOIN bugs
+          INNER JOIN bugs
                   ON flags.bug_id = bugs.bug_id
-                LEFT JOIN products
+           LEFT JOIN products
                   ON bugs.product_id = products.id
-                LEFT JOIN components
+           LEFT JOIN components
                   ON bugs.component_id = components.id
-                LEFT JOIN bug_group_map AS bgmap
+           LEFT JOIN bug_group_map AS bgmap
                   ON bgmap.bug_id = bugs.bug_id
-                LEFT JOIN user_group_map AS ugmap
-                  ON bgmap.group_id = ugmap.group_id
-                  AND ugmap.user_id = $::userid
-                  AND ugmap.isbless = 0
-                LEFT JOIN cc AS ccmap
+                 AND bgmap.group_id NOT IN (" .
+                     join(', ', (-1, values(%{Bugzilla->user->groups}))) . ")
+           LEFT JOIN cc AS ccmap
                   ON ccmap.who = $::userid
-                  AND ccmap.bug_id = bugs.bug_id
-    ";
+                 AND ccmap.bug_id = bugs.bug_id\r
+    " .
+
+    # Weed out bug the user does not have access to
+    " WHERE     ((bgmap.group_id IS NULL) OR
+                 (ccmap.who IS NOT NULL AND cclist_accessible = 1) OR
+                 (bugs.reporter = $::userid AND bugs.reporter_accessible = 1) OR
+                 (bugs.assigned_to = $::userid))";
     
     # Non-deleted flags only
-    $query .= " WHERE flags.is_active = 1 ";
+    $query .= " AND flags.is_active = 1 ";
     
     # Limit query to pending requests.
     $query .= " AND flags.status = '?' " unless $cgi->param('status');
@@ -215,7 +211,6 @@ sub queue {
                 requestees.login_name, flags.creation_date,
                 cclist_accessible, bugs.reporter, bugs.reporter_accessible,
                 bugs.assigned_to');
-    $query .= " HAVING cntuseringroups = cntbugingroups OR canseeanyway ";
 
     # Group the records, in other words order them by the group column
     # so the loop in the display template can break them up into separate