Commit 666d1f4b authored by mkanat%kerio.com's avatar mkanat%kerio.com

Bug 286360: ANSI SQL does not allow aliases to be used in HAVING clause

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