From: Peter Rabbitson Date: Fri, 15 Jan 2010 00:31:58 +0000 (+0000) Subject: Strict mysql bugfix X-Git-Tag: v0.08116~56 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0ce4ab92f5cb558e0f145eee2e52b8e213092045;p=dbsrgits%2FDBIx-Class.git Strict mysql bugfix --- diff --git a/Changes b/Changes index a7c383b..73c424f 100644 --- a/Changes +++ b/Changes @@ -15,6 +15,8 @@ Revision history for DBIx::Class search_related from prefetching resultsets - Fix regression on all-null returning searches (properly switch LEFT JOIN to JOIN in order to distinguish between both cases) + - Fix regression in groupedresultset count() used on strict-mode + MySQL connections - Better isolation of RNO-limited queries from the rest of a prefetching resultset - New MSSQL specific resultset attribute to allow hacky ordered diff --git a/lib/DBIx/Class/Storage/DBI/AmbiguousGlob.pm b/lib/DBIx/Class/Storage/DBI/AmbiguousGlob.pm index d883d0b..2008c54 100644 --- a/lib/DBIx/Class/Storage/DBI/AmbiguousGlob.pm +++ b/lib/DBIx/Class/Storage/DBI/AmbiguousGlob.pm @@ -27,6 +27,9 @@ At this point the only overriden method is C<_subq_count_select()> sub _subq_count_select { my ($self, $source, $rs_attrs) = @_; + + return $rs_attrs->{group_by} if $rs_attrs->{group_by}; + my @pcols = map { join '.', $rs_attrs->{alias}, $_ } ($source->primary_columns); return @pcols ? \@pcols : [ 1 ]; } diff --git a/t/71mysql.t b/t/71mysql.t index aa2db86..b51947c 100644 --- a/t/71mysql.t +++ b/t/71mysql.t @@ -225,6 +225,23 @@ NULLINSEARCH: { => 'Nothing Found!'; } +# check for proper grouped counts +{ + my $ansi_schema = DBICTest::Schema->connect ($dsn, $user, $pass, { on_connect_call => 'set_strict_mode' }); + my $rs = $ansi_schema->resultset('CD'); + + my $years; + $years->{$_->year|| scalar keys %$years}++ for $rs->all; # NULL != NULL, thus the keys eval + + lives_ok ( sub { + is ( + $rs->search ({}, { group_by => 'year'})->count, + scalar keys %$years, + 'grouped count correct', + ); + }, 'Grouped count does not throw'); +} + ZEROINSEARCH: { my $cds_per_year = { 2001 => 2,