2 use warnings FATAL => 'all';
7 eval "use SQL::Abstract 1.49";
9 ? ( skip_all => "Needs SQLA 1.49+" )
15 use DBIC::SqlMakerTest;
17 my $schema = DBICTest->init_schema();
18 my $art_rs = $schema->resultset('Artist');
19 my $cdrs = $schema->resultset('CD');
22 my $cdrs2 = $cdrs->search({
23 artist_id => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'id' )->as_query },
28 "(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 my $rs = $art_rs->search(
38 $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
45 "(SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me)",
51 my $rs = $art_rs->search(
55 $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
62 "(SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me)",
69 my $rs = $cdrs->search(
74 { cd2 => $cdrs->search({ id => { '>' => 20 } })->as_query },
81 "(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)",
90 my $art_rs2 = $schema->resultset('Artist')->search({},
92 from => [ { 'me' => 'artist' },
93 [ { 'cds' => $cdrs->search({},{ 'select' => [\'me.artist as cds_artist' ]})->as_query },
94 { 'me.artistid' => 'cds_artist' } ] ]
99 "(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)",
106 # nested subquery in from
108 my $rs = $cdrs->search(
113 { cd2 => $cdrs->search(
114 { id => { '>' => 20 } },
118 { cd3 => $cdrs->search( { id => { '<' => 40 } } )->as_query }
127 "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track
129 (SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track
131 (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track
132 FROM cd me WHERE ( id < ? ) ) cd3
133 WHERE ( id > ? ) ) cd2)",
143 my $rs = $cdrs->search({
145 '=' => $cdrs->search(
146 { artistid => { '=' => \'me.artistid' } },
148 )->get_column('year')->max_rs->as_query,
153 "(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))",
159 my $rs = $cdrs->search(
164 { cd2 => $cdrs->search({ title => 'Thriller' })->as_query },
171 "(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)",
172 [ [ 'title', 'Thriller' ] ],