13 use DBIC::SqlMakerTest;
15 my $schema = DBICTest->init_schema();
16 my $art_rs = $schema->resultset('Artist');
17 my $cdrs = $schema->resultset('CD');
23 artist_id => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'id' )->as_query },
26 "( SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE artist_id IN ( SELECT id FROM artist me LIMIT 1 ) )",
34 $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
38 "( SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me )",
46 $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
50 "( SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me )",
59 { cd2 => $cdrs->search({ id => { '>' => 20 } })->as_query },
63 "( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE id > ?) cd2 )",
71 from => [ { 'me' => 'artist' },
72 [ { 'cds' => $cdrs->search({},{ 'select' => [\'me.artist as cds_artist' ]})->as_query },
73 { 'me.artistid' => 'cds_artist' } ] ]
76 "( SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me JOIN (SELECT me.artist as cds_artist FROM cd me) cds ON me.artistid = cds_artist )"
85 { cd2 => $cdrs->search(
86 { id => { '>' => 20 } },
90 { cd3 => $cdrs->search( { id => { '<' => 40 } } )->as_query }
96 "( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track
98 (SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track
100 (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track
101 FROM cd me WHERE id < ?) cd3
113 '=' => $cdrs->search(
114 { artistid => { '=' => \'me.artistid' } },
116 )->get_column('year')->max_rs->as_query,
120 "( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE year = (SELECT MAX(inner.year) FROM cd inner WHERE artistid = me.artistid) )",
129 { cd2 => $cdrs->search({ title => 'Thriller' })->as_query },
133 "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE title = ?) cd2)",
142 plan tests => @tests * 2;
144 for my $i (0 .. $#tests) {
146 for my $p (1, 2) { # repeat everything twice, make sure we do not clobber search arguments
148 $t->{rs}->search ($t->{search}, $t->{attrs})->as_query,
150 sprintf 'Testcase %d, pass %d', $i+1, $p,