Commit | Line | Data |
59af6677 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings FATAL => 'all'; |
5 | |
70eb901c |
6 | use Data::Dumper; |
7 | |
59af6677 |
8 | use Test::More; |
d0a3e4e2 |
9 | |
4abc8be6 |
10 | plan ( tests => 5 ); |
d0a3e4e2 |
11 | |
59af6677 |
12 | use lib qw(t/lib); |
13 | use DBICTest; |
152d414d |
14 | use DBIC::SqlMakerTest; |
59af6677 |
15 | |
4dc99a01 |
16 | my $schema = DBICTest->init_schema(); |
17 | my $art_rs = $schema->resultset('Artist'); |
18 | my $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 |
47 | my $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 | } |