2 use warnings FATAL => 'all';
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 (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE ( id > ? ) ) cd2)",
85 my $art_rs2 = $schema->resultset('Artist')->search({},
87 from => [ { 'me' => 'artist' },
88 [ { 'cds' => $cdrs->search({},{ 'select' => [\'me.artist as cds_artist' ]})->as_query },
89 { 'me.artistid' => 'cds_artist' } ] ]
94 "(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)",
101 # nested subquery in from
103 my $rs = $cdrs->search(
108 { cd2 => $cdrs->search(
109 { id => { '>' => 20 } },
113 { cd3 => $cdrs->search( { id => { '<' => 40 } } )->as_query }
122 "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track
124 (SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track
126 (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track
127 FROM cd me WHERE ( id < ? ) ) cd3
128 WHERE ( id > ? ) ) cd2)",
138 my $rs = $cdrs->search({
140 '=' => $cdrs->search(
141 { artistid => { '=' => \'me.artistid' } },
143 )->get_column('year')->max_rs->as_query,
148 "(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))",
154 my $rs = $cdrs->search(
159 { cd2 => $cdrs->search({ title => 'Thriller' })->as_query },
166 "(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)",
167 [ [ 'title', 'Thriller' ] ],