[Bast-commits] r5516 - in DBIx-Class/0.08/branches/subquery: lib/DBIx/Class t/search

robkinyon at dev.catalyst.perl.org robkinyon at dev.catalyst.perl.org
Wed Feb 18 03:06:02 GMT 2009


Author: robkinyon
Date: 2009-02-18 03:06:02 +0000 (Wed, 18 Feb 2009)
New Revision: 5516

Modified:
   DBIx-Class/0.08/branches/subquery/lib/DBIx/Class/ResultSetColumn.pm
   DBIx-Class/0.08/branches/subquery/t/search/subquery.t
Log:
The tests are truly failing tests

Modified: DBIx-Class/0.08/branches/subquery/lib/DBIx/Class/ResultSetColumn.pm
===================================================================
--- DBIx-Class/0.08/branches/subquery/lib/DBIx/Class/ResultSetColumn.pm	2009-02-18 02:50:16 UTC (rev 5515)
+++ DBIx-Class/0.08/branches/subquery/lib/DBIx/Class/ResultSetColumn.pm	2009-02-18 03:06:02 UTC (rev 5516)
@@ -186,6 +186,24 @@
   return shift->func('MIN');
 }
 
+=head2 min_rs
+
+=over 4
+
+=item Arguments: none
+
+=item Return Value: $resultset
+
+=back
+
+  my $rs = $year_col->min_rs();
+
+Wrapper for ->func_rs for function MIN().
+
+=cut
+
+sub min_rs { return shift->func_rs('MIN') }
+
 =head2 max
 
 =over 4
@@ -207,6 +225,24 @@
   return shift->func('MAX');
 }
 
+=head2 max_rs
+
+=over 4
+
+=item Arguments: none
+
+=item Return Value: $resultset
+
+=back
+
+  my $rs = $year_col->max_rs();
+
+Wrapper for ->func_rs for function MAX().
+
+=cut
+
+sub max_rs { return shift->func_rs('MAX') }
+
 =head2 sum
 
 =over 4
@@ -228,6 +264,24 @@
   return shift->func('SUM');
 }
 
+=head2 sum_rs
+
+=over 4
+
+=item Arguments: none
+
+=item Return Value: $resultset
+
+=back
+
+  my $rs = $year_col->sum_rs();
+
+Wrapper for ->func_rs for function SUM().
+
+=cut
+
+sub sum_rs { return shift->func_rs('SUM') }
+
 =head2 func
 
 =over 4
@@ -250,7 +304,7 @@
 
 sub func {
   my ($self,$function) = @_;
-  my $cursor = $self->{_parent_resultset}->search(undef, {select => {$function => $self->{_select}}, as => [$self->{_as}]})->cursor;
+  my $cursor = $self->func_rs($function)->cursor;
   
   if( wantarray ) {
     return map { $_->[ 0 ] } $cursor->all;
@@ -259,6 +313,30 @@
   return ( $cursor->next )[ 0 ];
 }
 
+=head2 func_rs
+
+=over 4
+
+=item Arguments: $function
+
+=item Return Value: $resultset
+
+=back
+
+Creates the resultset that C<func()> uses to run its query.
+
+=cut
+
+sub func_rs {
+  my ($self,$function) = @_;
+  return $self->{_parent_resultset}->search(
+    undef, {
+      select => {$function => $self->{_select}},
+      as => [$self->{_as}],
+    },
+  );
+}
+
 =head2 throw_exception
 
 See L<DBIx::Class::Schema/throw_exception> for details.

Modified: DBIx-Class/0.08/branches/subquery/t/search/subquery.t
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/search/subquery.t	2009-02-18 02:50:16 UTC (rev 5515)
+++ DBIx-Class/0.08/branches/subquery/t/search/subquery.t	2009-02-18 03:06:02 UTC (rev 5516)
@@ -10,7 +10,7 @@
 use DBICTest;
 use DBIC::SqlMakerTest;
 
-plan tests => 3;
+plan tests => 4;
 
 my $schema = DBICTest->init_schema();
 my $art_rs = $schema->resultset('Artist');
@@ -31,7 +31,7 @@
 }
 
 TODO: {
-  local $TODO = "'+select' doesn't work with as_query yet.";
+#  local $TODO = "'+select' doesn't work with as_query yet.";
   my $rs = $art_rs->search(
     {},
     {
@@ -55,7 +55,7 @@
 }
 
 TODO: {
-  local $TODO = "'from' doesn't work with as_query yet.";
+#  local $TODO = "'from' doesn't work with as_query yet.";
   my $rs = $cdrs->search(
     {},
     {
@@ -75,4 +75,23 @@
   );
 }
 
+TODO: {
+#  local $TODO = "The subquery isn't being wrapped in parens for some reason.";
+  my $rs = $cdrs->search({
+    year => {
+      '=' => $cdrs->search(
+        { artistid => { '=' => \'me.artistid' } },
+        { alias => 'inner' }
+      )->get_column('year')->max_rs->as_query,
+    },
+  });
+  my $arr = $rs->as_query;
+  my ($query, @bind) = @{$$arr};
+  is_same_sql_bind(
+    $query, \@bind,
+    "SELECT me.cdid, me.artistid, me.rank, me.charfield FROM cd me WHERE year = (SELECT MAX(inner.year) FROM cd inner WHERE artistid = me.artistid)",
+    [],
+  );
+}
+
 __END__




More information about the Bast-commits mailing list