From 45fa6da5482cd29ab7e849c83eb98c3c3cc3b9b1 Mon Sep 17 00:00:00 2001 From: "bugreport%peshkin.net" <> Date: Sat, 1 Jan 2005 09:25:56 +0000 Subject: [PATCH] Bug 245158: Combine multiple left joins of same table within a chart so Search.pm doesn't fail. r=zach,justdave a=justdave --- Bugzilla/Search.pm | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index 75307a0e32..374501d86f 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -1000,6 +1000,8 @@ sub init { # @supptables = Tables and/or table aliases used in query # %suppseen = A hash used to store all the tables in supptables to weed # out duplicates. +# @supplist = A list used to accumulate all the JOIN clauses for each +# chart to merge the ON sections of each. # $suppstring = String which is pasted into query containing all table names # get a list of field names to verify the user-submitted chart fields against @@ -1081,15 +1083,25 @@ sub init { } my %suppseen = ("bugs" => 1); my $suppstring = "bugs"; + my @supplist = (" "); foreach my $str (@supptables) { if (!$suppseen{$str}) { - if ($str !~ /^(LEFT|INNER) JOIN/i) { - $suppstring .= ","; + if ($str =~ /^(LEFT|INNER) JOIN/i) { + $str =~ /^(.*?)\s+ON\s+(.*)$/i; + my ($leftside, $rightside) = ($1, $2); + if ($suppseen{$leftside}) { + $supplist[$suppseen{$leftside}] .= " AND ($rightside)"; + } else { + $suppseen{$leftside} = scalar @supplist; + push @supplist, " $leftside ON ($rightside)"; + } + } else { + $suppstring .= ", $str"; + $suppseen{$str} = 1; } - $suppstring .= " $str"; - $suppseen{$str} = 1; } } + $suppstring .= join('', @supplist); # Make sure we create a legal SQL query. @andlist = ("1 = 1") if !@andlist; -- 2.47.2