From: Peter Rabbitson Date: Thu, 7 May 2009 17:53:30 +0000 (+0000) Subject: Adjust tests for the IN fixes X-Git-Tag: v0.08103~101^2~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5a825e673241638c4bc1fcc93238ceb4df5ca49d;p=dbsrgits%2FDBIx-Class.git Adjust tests for the IN fixes --- diff --git a/t/count/count_distinct.t b/t/count/count_distinct.t index d4dd422..97cb7f9 100644 --- a/t/count/count_distinct.t +++ b/t/count/count_distinct.t @@ -30,22 +30,28 @@ $rs = $schema->resultset('Tag')->search({ tag => 'Blue' }, { distinct => 1 }); is($rs->count, 4, 'Count with single column distinct'); $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }); -is($rs->count, 4, 'Count with IN subquery'); +#SELECT COUNT( * ) FROM tags me WHERE ( tag IN ( SELECT me.tag FROM tags me WHERE ( ( tag = ? OR tag = ? ) ) ) ): 'Blue', 'Shiny' +is($rs->count, 6, 'Count with IN subquery'); $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { group_by => 'tag' }); -is($rs->count, 1, 'Count with IN subquery with outside group_by'); +#SELECT COUNT( * ) FROM (SELECT tag FROM tags me WHERE ( tag IN ( SELECT me.tag FROM tags me WHERE ( ( tag = ? OR tag = ? ) ) ) ) GROUP BY tag) mesub: 'Blue', 'Shiny' +is($rs->count, 2, 'Count with IN subquery with outside group_by'); $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { distinct => 1 }); -is($rs->count, 4, 'Count with IN subquery with outside distinct'); +#SELECT COUNT( * ) FROM (SELECT me.tagid, me.cd, me.tag FROM tags me WHERE ( tag IN ( SELECT me.tag FROM tags me WHERE ( ( tag = ? OR tag = ? ) ) ) ) GROUP BY me.tagid, me.cd, me.tag) mesub: 'Blue', 'Shiny' +is($rs->count, 6, 'Count with IN subquery with outside distinct'); $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { distinct => 1, select => 'tag' }), -is($rs->count, 1, 'Count with IN subquery with outside distinct on a single column'); +#SELECT COUNT( * ) FROM (SELECT tag FROM tags me WHERE ( tag IN ( SELECT me.tag FROM tags me WHERE ( ( tag = ? OR tag = ? ) ) ) ) GROUP BY tag) mesub: 'Blue', 'Shiny' +is($rs->count, 2, 'Count with IN subquery with outside distinct on a single column'); $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->search({}, { group_by => 'tag' })->get_column('tag')->as_query } }); -is($rs->count, 4, 'Count with IN subquery with single group_by'); +#SELECT COUNT( * ) FROM tags me WHERE ( tag IN ( SELECT me.tag FROM tags me WHERE ( ( tag = ? OR tag = ? ) ) GROUP BY tag ) ): 'Blue', 'Shiny' +is($rs->count, 6, 'Count with IN subquery with single group_by'); $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->search({}, { group_by => [ qw/tag cd/ ] })->get_column('tag')->as_query } }); -is($rs->count, 4, 'Count with IN subquery with multiple group_by'); +#SELECT COUNT( * ) FROM tags me WHERE ( tag IN ( SELECT me.tag FROM tags me WHERE ( ( tag = ? OR tag = ? ) ) GROUP BY tag, cd ) ): 'Blue', 'Shiny' +is($rs->count, 6, 'Count with IN subquery with multiple group_by'); $rs = $schema->resultset('Tag')->search({ tag => \"= 'Blue'" }); is($rs->count, 4, 'Count without DISTINCT, using literal SQL'); diff --git a/t/resultset/as_query.t b/t/resultset/as_query.t index f849f7a..f3a09fc 100644 --- a/t/resultset/as_query.t +++ b/t/resultset/as_query.t @@ -66,12 +66,11 @@ my $rscol = $art_rs->get_column( 'charfield' ); ); } -TODO: { - local $TODO = 'Needs -paren fixes in SQLA before it can work'; - my $rs = $schema->resultset("CD")->search( - { 'artist.name' => 'Caterwauler McCrae' }, - { join => [qw/artist/]} - ); - my $subsel_rs = $schema->resultset("CD")->search( { cdid => { IN => $rs->get_column('cdid')->as_query } } ); - cmp_ok($subsel_rs->count, '==', $rs->count, 'Subselect on PK got the same row count'); +{ + my $rs = $schema->resultset("CD")->search( + { 'artist.name' => 'Caterwauler McCrae' }, + { join => [qw/artist/]} + ); + my $subsel_rs = $schema->resultset("CD")->search( { cdid => { IN => $rs->get_column('cdid')->as_query } } ); + is($subsel_rs->count, $rs->count, 'Subselect on PK got the same row count'); }