[Bast-commits] r5749 - in DBIx-Class/0.08/branches/count_distinct: lib/DBIx lib/DBIx/Class lib/DBIx/Class/Storage t

arcanez at dev.catalyst.perl.org arcanez at dev.catalyst.perl.org
Fri Mar 13 05:45:32 GMT 2009


Author: arcanez
Date: 2009-03-13 05:45:32 +0000 (Fri, 13 Mar 2009)
New Revision: 5749

Added:
   DBIx-Class/0.08/branches/count_distinct/t/distinct_count.t
Modified:
   DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class.pm
   DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class/ResultSet.pm
   DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class/Storage/DBI.pm
Log:
changes to handling of from

Modified: DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class/ResultSet.pm	2009-03-13 04:20:32 UTC (rev 5748)
+++ DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class/ResultSet.pm	2009-03-13 05:45:32 UTC (rev 5749)
@@ -1156,7 +1156,6 @@
   # 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;

Modified: DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class/Storage/DBI.pm	2009-03-13 04:20:32 UTC (rev 5748)
+++ DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class/Storage/DBI.pm	2009-03-13 05:45:32 UTC (rev 5749)
@@ -96,17 +96,19 @@
 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);

Modified: DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class.pm	2009-03-13 04:20:32 UTC (rev 5748)
+++ DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class.pm	2009-03-13 05:45:32 UTC (rev 5749)
@@ -323,6 +323,8 @@
 
 norbi: Norbert Buchmuller <norbi at nix.hu>
 
+arcanez: Justin Hunter <justin.d.hunter at gmail.com>
+
 =head1 LICENSE
 
 You may distribute this code under the same terms as Perl itself.

Added: DBIx-Class/0.08/branches/count_distinct/t/distinct_count.t
===================================================================
--- DBIx-Class/0.08/branches/count_distinct/t/distinct_count.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/count_distinct/t/distinct_count.t	2009-03-13 05:45:32 UTC (rev 5749)
@@ -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");
+




More information about the Bast-commits mailing list