From: Rob Kinyon Date: Wed, 18 Feb 2009 03:06:02 +0000 (+0000) Subject: The tests are truly failing tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4fa7bc220537c54f6cb7ca6d2ff7b3c0f68e1233;p=dbsrgits%2FDBIx-Class-Historic.git The tests are truly failing tests --- diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index 2a7ce97..3248ecb 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -186,6 +186,24 @@ sub min { 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 @@ sub max { 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 @@ sub sum { 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 @@ value. Produces the following SQL: 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 @@ sub func { return ( $cursor->next )[ 0 ]; } +=head2 func_rs + +=over 4 + +=item Arguments: $function + +=item Return Value: $resultset + +=back + +Creates the resultset that C 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 for details. diff --git a/t/search/subquery.t b/t/search/subquery.t index 5b54d7a..ed91419 100644 --- a/t/search/subquery.t +++ b/t/search/subquery.t @@ -10,7 +10,7 @@ use lib qw(t/lib); 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 @@ my $cdrs = $schema->resultset('CD'); } 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 @@ warn "$query\n"; } 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: { ); } +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__