[Bast-commits] r5470 - DBIx-Class/0.08/branches/subquery/t/resultset
robkinyon at dev.catalyst.perl.org
robkinyon at dev.catalyst.perl.org
Fri Feb 13 19:56:41 GMT 2009
Author: robkinyon
Date: 2009-02-13 19:56:40 +0000 (Fri, 13 Feb 2009)
New Revision: 5470
Modified:
DBIx-Class/0.08/branches/subquery/t/resultset/as_query.t
Log:
Added a passing test for initial simple subqueries
Modified: DBIx-Class/0.08/branches/subquery/t/resultset/as_query.t
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/resultset/as_query.t 2009-02-13 19:43:12 UTC (rev 5469)
+++ DBIx-Class/0.08/branches/subquery/t/resultset/as_query.t 2009-02-13 19:56:40 UTC (rev 5470)
@@ -10,7 +10,7 @@
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({ 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 @@
[ [ 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__
More information about the Bast-commits
mailing list