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

arcanez at dev.catalyst.perl.org arcanez at dev.catalyst.perl.org
Mon May 11 20:41:21 GMT 2009


Author: arcanez
Date: 2009-05-11 20:41:21 +0000 (Mon, 11 May 2009)
New Revision: 6212

Modified:
   DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class/Storage/DBI.pm
   DBIx-Class/0.08/branches/count_distinct/t/count/count_distinct.t
Log:
warn/die based on { select => { distinct => { } } }

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-05-11 19:23:01 UTC (rev 6211)
+++ DBIx-Class/0.08/branches/count_distinct/lib/DBIx/Class/Storage/DBI.pm	2009-05-11 20:41:21 UTC (rev 6212)
@@ -223,6 +223,22 @@
       } @$fields);
   } elsif ($ref eq 'HASH') {
     foreach my $func (keys %$fields) {
+      if ($func eq 'distinct') {
+        my $_fields = $fields->{$func};
+        if (ref $_fields eq 'ARRAY' && @{$_fields} > 1) {
+          die "Unsupported syntax, please use " . 
+              "{ group_by => [ qw/" . (join ' ', @$_fields) . "/ ] }" .
+              " or " .
+              "{ select => [ qw/" . (join ' ', @$_fields) . "/ ], distinct => 1 }";
+        }
+        else {
+          warn "This syntax will be deprecated in 09, please use " . 
+               "{ group_by => '${_fields}' }" . 
+               " or " .
+               "{ select => '${_fields}', distinct => 1 }";
+        }
+      }
+      
       return $self->_sqlcase($func)
         .'( '.$self->_recurse_fields($fields->{$func}).' )';
     }

Modified: DBIx-Class/0.08/branches/count_distinct/t/count/count_distinct.t
===================================================================
--- DBIx-Class/0.08/branches/count_distinct/t/count/count_distinct.t	2009-05-11 19:23:01 UTC (rev 6211)
+++ DBIx-Class/0.08/branches/count_distinct/t/count/count_distinct.t	2009-05-11 20:41:21 UTC (rev 6212)
@@ -2,6 +2,7 @@
 use warnings;  
 
 use Test::More;
+use Test::Exception;
 
 use lib qw(t/lib);
 
@@ -12,7 +13,7 @@
 
 eval "use DBD::SQLite";
 plan skip_all => 'needs DBD::SQLite for testing' if $@;
-plan tests => 16;
+plan tests => 18;
 
 # The tag Blue is assigned to cds 1 2 3 and 5
 # The tag Cheesy is assigned to cds 2 4 and 5
@@ -69,3 +70,13 @@
 
 $rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Cheesy')" }, { group_by => [ qw/tag cd/ ] });
 is($rs->count, 7, 'Count with literal SQL and multiple group_by');
+
+my @warnings;
+{
+  local $SIG{__WARN__} = sub { push @warnings, shift };
+  my $row = $schema->resultset('Tag')->search({}, { select => { distinct => 'tag' } })->first;
+}
+
+is(@warnings, 1, 'expecteing warn');
+
+dies_ok(sub { my $row = $schema->resultset('Tag')->search({}, { select => { distinct => [qw/tag cd/] } })->first }, 'expecting to die');




More information about the Bast-commits mailing list