10 use DBIC::SqlMakerTest;
12 my $schema = DBICTest->init_schema();
13 my $art_rs = $schema->resultset('Artist');
14 my $cdrs = $schema->resultset('CD');
19 search => \[ "title = ? AND year LIKE ?", 'buahaha', '20%' ],
20 attrs => { rows => 5 },
22 "( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE (title = ? AND year LIKE ?) LIMIT 5)",
31 artist_id => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'id' )->as_query },
34 "( 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 ) )",
42 $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
46 "( SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me )",
54 $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
58 "( SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me )",
67 { cd2 => $cdrs->search({ id => { '>' => 20 } })->as_query },
71 "( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (
72 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE id > ?
85 { 'cds' => $cdrs->search({}, { 'select' => [\'me.artist as cds_artist' ]})->as_query },
86 { 'me.artistid' => 'cds_artist' }
91 "( 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 )"
100 { cd2 => $cdrs->search(
101 { id => { '>' => 20 } },
105 { cd3 => $cdrs->search( { id => { '<' => 40 } } )->as_query }
111 "( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track
113 (SELECT cd3.cdid, cd3.artist, cd3.title, cd3.year, cd3.genreid, cd3.single_track
115 (SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
116 FROM cd me WHERE id < ?) cd3
128 '=' => $cdrs->search(
129 { artistid => { '=' => \'me.artistid' } },
131 )->get_column('year')->max_rs->as_query,
135 "( 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) )",
144 { cd2 => $cdrs->search({ title => 'Thriller' })->as_query },
148 "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (
149 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE title = ?
160 plan tests => @tests * 2;
162 for my $i (0 .. $#tests) {
164 for my $p (1, 2) { # repeat everything twice, make sure we do not clobber search arguments
166 $t->{rs}->search ($t->{search}, $t->{attrs})->as_query,
168 sprintf 'Testcase %d, pass %d', $i+1, $p,