8 use DBIC::SqlMakerTest;
12 my $schema = DBICTest->init_schema();
13 my $art_rs = $schema->resultset('Artist');
14 my $cdrs = $schema->resultset('CD');
17 my $cdrs2 = $cdrs->search({
18 artist_id => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'id' )->as_query },
23 "(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 ))",
29 my $rs = $art_rs->search(
33 $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
40 "(SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me)",
46 my $rs = $art_rs->search(
50 $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
57 "(SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me)",
64 my $rs = $cdrs->search(
69 { cd2 => $cdrs->search({ id => { '>' => 20 } })->as_query },
76 "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (
77 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( id > ? )
87 my $art_rs2 = $schema->resultset('Artist')->search({},
89 from => [ { 'me' => 'artist' },
90 [ { 'cds' => $cdrs->search({},{ 'select' => [\'me.artist as cds_artist' ]})->as_query },
91 { 'me.artistid' => 'cds_artist' } ] ]
96 "(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)",
103 # nested subquery in from
105 my $rs = $cdrs->search(
110 { cd2 => $cdrs->search(
111 { id => { '>' => 20 } },
115 { cd3 => $cdrs->search( { id => { '<' => 40 } } )->as_query }
124 "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track
126 (SELECT cd3.cdid, cd3.artist, cd3.title, cd3.year, cd3.genreid, cd3.single_track
128 (SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
129 FROM cd me WHERE ( id < ? ) ) cd3
130 WHERE ( id > ? ) ) cd2)",
140 my $rs = $cdrs->search({
142 '=' => $cdrs->search(
143 { artistid => { '=' => \'me.artistid' } },
145 )->get_column('year')->max_rs->as_query,
150 "(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))",
156 my $rs = $cdrs->search(
161 { cd2 => $cdrs->search({ title => 'Thriller' })->as_query },
168 "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (
169 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( title = ? )
171 [ [ 'title', 'Thriller' ] ],