more dt docs reorg
[dbsrgits/DBIx-Class.git] / t / resultset / as_query.t
CommitLineData
59af6677 1#!/usr/bin/perl
2
3use strict;
4use warnings FATAL => 'all';
5
70eb901c 6use Data::Dumper;
7
59af6677 8use Test::More;
d0a3e4e2 9
4abc8be6 10plan ( tests => 5 );
d0a3e4e2 11
59af6677 12use lib qw(t/lib);
13use DBICTest;
152d414d 14use DBIC::SqlMakerTest;
59af6677 15
4dc99a01 16my $schema = DBICTest->init_schema();
17my $art_rs = $schema->resultset('Artist');
18my $cdrs = $schema->resultset('CD');
59af6677 19
20{
152d414d 21 is_same_sql_bind(
af6aac2d 22 $art_rs->as_query,
45594863 23 "(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me)", [],
152d414d 24 );
59af6677 25}
26
27$art_rs = $art_rs->search({ name => 'Billy Joel' });
28
29{
152d414d 30 is_same_sql_bind(
af6aac2d 31 $art_rs->as_query,
45594863 32 "(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE ( name = ? ))",
152d414d 33 [ [ name => 'Billy Joel' ] ],
34 );
59af6677 35}
36
37$art_rs = $art_rs->search({ rank => 2 });
38
39{
152d414d 40 is_same_sql_bind(
af6aac2d 41 $art_rs->as_query,
45594863 42 "(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE ( ( ( rank = ? ) AND ( name = ? ) ) ) )",
152d414d 43 [ [ rank => 2 ], [ name => 'Billy Joel' ] ],
44 );
59af6677 45}
46
658fa250 47my $rscol = $art_rs->get_column( 'charfield' );
48
49{
152d414d 50 is_same_sql_bind(
af6aac2d 51 $rscol->as_query,
45594863 52 "(SELECT me.charfield FROM artist me WHERE ( ( ( rank = ? ) AND ( name = ? ) ) ) )",
152d414d 53 [ [ rank => 2 ], [ name => 'Billy Joel' ] ],
54 );
658fa250 55}
70eb901c 56
5a825e67 57{
58 my $rs = $schema->resultset("CD")->search(
59 { 'artist.name' => 'Caterwauler McCrae' },
60 { join => [qw/artist/]}
61 );
62 my $subsel_rs = $schema->resultset("CD")->search( { cdid => { IN => $rs->get_column('cdid')->as_query } } );
63 is($subsel_rs->count, $rs->count, 'Subselect on PK got the same row count');
4abc8be6 64}