From: Justin Hunter Date: Fri, 13 Mar 2009 05:45:32 +0000 (+0000) Subject: changes to handling of from X-Git-Tag: v0.08103~101^2~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4c26f1855be6e178f43d57700bd18ee1f51bffd6;p=dbsrgits%2FDBIx-Class.git changes to handling of from --- diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index bb73581..d9a2012 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -323,6 +323,8 @@ zamolxes: Bogdan Lucaciu norbi: Norbert Buchmuller +arcanez: Justin Hunter + =head1 LICENSE You may distribute this code under the same terms as Perl itself. diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index f4ac871..cffc524 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1156,7 +1156,6 @@ sub _count { # Separated out so pager can get the full count # offset, order by, group by, where and page are not needed to count. record_filter is cdbi delete $attrs->{$_} for qw/rows offset order_by group_by where page pager record_filter/; - $self->result_source->resultset; my $tmp_rs = (ref $self)->new($self->result_source, $attrs); my ($count) = $tmp_rs->cursor->next; return $count; diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 09dc92a..54491a7 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -96,17 +96,19 @@ sub _find_syntax { sub select { my ($self, $table, $fields, $where, $order, @rest) = @_; local $self->{having_bind} = []; + +# if (ref $table eq 'HASH') { +# my $alias; +# ($alias, $table) = %$table; +# } + if (ref $table eq 'SCALAR') { $table = $$table; } - elsif (ref $table eq 'HASH') { - ## what if they want to alias a sub query? - } elsif (ref $table eq 'REF') { - #my ($sql, @bind) = @{${$t}}; push(@{$self->{having_bind}}, @bind;); - my $t = $table; - $table = shift @$$t; - while (my $b = shift @$$t) { push @{$self->{having_bind}}, $b; } + my ($sql, @bind) = @{${$table}}; + push(@{$self->{having_bind}}, @bind); + $table = $sql; } elsif (not ref $table) { $table = $self->_quote($table); diff --git a/t/distinct_count.t b/t/distinct_count.t new file mode 100644 index 0000000..b3f3446 --- /dev/null +++ b/t/distinct_count.t @@ -0,0 +1,26 @@ +use strict; +use warnings; + +use Test::More; +use lib qw(t/lib); +use lib '/sporkrw/xfer/DBIx-Class/0.08/branches/count_distinct/lib'; +use DBICTest; + +my $schema = DBICTest->init_schema(); + +eval "use DBD::SQLite"; +plan skip_all => 'needs DBD::SQLite for testing' if $@; +plan tests => 4; + +cmp_ok($schema->resultset("Tag")->count({ tag => 'Blue' }), + '==', 9, 'Count without DISTINCT ok'); + +cmp_ok($schema->resultset("Tag")->count({ tag => [ 'Blue', 'Shiny' ] }, { group_by => 'tag' }), + '==', 2, 'Count with single column group_by ok'); + +cmp_ok($schema->resultset("Tag")->count({ tag => 'Blue' }, { group_by => [ qw/tag cd/ ]}), + '==', 4, 'Count with multiple column group_by ok'); + +cmp_ok($schema->resultset("Tag")->count({ tag => 'Blue' }, { distinct => 1 }), + '==', 4, "Count with single column distinct ok"); +