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
This commit is contained in:
mkanat%kerio.com 2005-04-16 00:37:23 +00:00
parent 9454bf5870
commit c9f941cf6b
2 changed files with 39 additions and 39 deletions

View 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";
# add the column not used in aggregate function explicitly
# 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";
}
},

View File

@ -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
" .
# 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