From: Rob Kinyon Date: Fri, 13 Feb 2009 19:56:40 +0000 (+0000) Subject: Added a passing test for initial simple subqueries X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=36d80a6bc4fd382919d7f74ec53aec5c2da5fca2;p=dbsrgits%2FDBIx-Class-Historic.git Added a passing test for initial simple subqueries --- diff --git a/t/resultset/as_query.t b/t/resultset/as_query.t index 97dd3e4..2929e7c 100644 --- a/t/resultset/as_query.t +++ b/t/resultset/as_query.t @@ -10,7 +10,7 @@ use lib qw(t/lib); use DBICTest; use DBIC::SqlMakerTest; -plan tests => 4; +plan tests => 5; my $schema = DBICTest->init_schema(); my $art_rs = $schema->resultset('Artist'); @@ -42,18 +42,16 @@ $art_rs = $art_rs->search({ name => 'Billy Joel' }); $art_rs = $art_rs->search({ rank => 2 }); { - my $arr = $art_rs->as_query; + my $arr = $art_rs->as_subselect; my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE ( ( ( rank = ? ) AND ( name = ? ) ) )", + "( SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE ( ( rank = ? ) AND ( name = ? ) ) )", [ [ rank => 2 ], [ name => 'Billy Joel' ] ], ); } -{my $sql = $art_rs->as_sql; warn "$sql\n";} - my $rscol = $art_rs->get_column( 'charfield' ); { @@ -66,19 +64,20 @@ my $rscol = $art_rs->get_column( 'charfield' ); [ [ rank => 2 ], [ name => 'Billy Joel' ] ], ); } -{my $sql = $rscol->as_sql; warn "$sql\n";} - -my $cdrs2 = $cdrs->search({ - artist_id => $art_rs->get_column( 'id' )->as_query, -}); -warn Dumper $cdrs2->as_query; -__END__ -my @x = $cdrs2->all; -warn Dumper \@x; { + my $cdrs2 = $cdrs->search({ + artist_id => { '=' => $art_rs->search({}, { rows => 1 })->get_column( 'id' )->as_subselect }, + }); + my $arr = $cdrs2->as_query; my ($query, @bind) = @{$$arr}; + is_same_sql_bind( + $query, \@bind, + "SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE artist_id = ( SELECT id FROM artist me WHERE ( rank = ? ) AND ( name = ? ) LIMIT 1 )", + [ [ rank => 2 ], [ name => 'Billy Joel' ] ], + ); +warn Dumper $cdrs2->as_sql; } __END__