From b99cbd1d893ff0a730ab7187f409bcdf3c6f4aeb Mon Sep 17 00:00:00 2001 From: "mkanat%kerio.com" <> Date: Wed, 16 Mar 2005 08:27:14 +0000 Subject: Bug 174295: ANSI SQL requires all columns in SELECT to be in GROUP BY, unless they are in "aggregate" functions Patch By Tomas Kopal r=joel, a=myk --- Bugzilla/DB.pm | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'Bugzilla/DB.pm') diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm index 098d10ba1..0d41bbd01 100644 --- a/Bugzilla/DB.pm +++ b/Bugzilla/DB.pm @@ -213,9 +213,14 @@ sub sql_position { return "POSITION($fragment IN $text)"; } -##################################################################### -# General Info Methods -##################################################################### +sub sql_group_by { + my ($self, $needed_columns, $optional_columns) = @_; + + my $expression = "GROUP BY $needed_columns"; + $expression .= ", " . $optional_columns if defined($optional_columns); + + return $expression; +} sub sql_string_concat { my ($self, @params) = @_; @@ -246,6 +251,10 @@ sub sql_fulltext_search { "%${quote}) THEN 1 ELSE 0 END"; } +##################################################################### +# General Info Methods +##################################################################### + # XXX - Needs to be documented. sub bz_server_version { my ($self) = @_; @@ -786,6 +795,21 @@ formatted SQL command have prefix C. All other methods have prefix C. $text = the text to search (scalar) Returns: formatted SQL for substring search (scalar) +=item C + + Description: Outputs proper SQL syntax for grouping the result of a query. + For ANSI SQL databases, we need to group by all columns we are + querying for (except for columns used in aggregate functions). + Some databases require (or even allow) to specify only one + or few columns if the result is uniquely defined. For those + databases, the default implementation needs to be overloaded. + Params: $needed_columns = string with comma separated list of columns + we need to group by to get expected result (scalar) + $optional_columns = string with comma separated list of all + other columns we are querying for, but which are not in the + required list. + Returns: formatted SQL for row grouping (scalar) + =item C Description: Returns SQL syntax for concatenating multiple strings (constants -- cgit v1.2.3-24-g4f1b