8 use DBIC::SqlMakerTest;
9 use DBIx::Class::SQLMaker::LimitDialects;
11 my $ROWS = DBIx::Class::SQLMaker::LimitDialects->__rows_bindtype;
13 my $schema = DBICTest->init_schema();
14 my $art_rs = $schema->resultset('Artist');
15 my $cdrs = $schema->resultset('CD');
20 search => \[ "title = ? AND year LIKE ?", [ title => 'buahaha' ], [ year => '20%' ] ],
21 attrs => { rows => 5 },
23 "( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE (title = ? AND year LIKE ?) LIMIT ?)",
24 [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'title' } => 'buahaha' ],
25 [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'year' } => '20%' ],
33 artistid => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'artistid' )->as_query },
36 "( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE artistid IN ( SELECT me.artistid FROM artist me LIMIT ? ) )",
45 $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
49 "( SELECT (SELECT me.id FROM cd me LIMIT ?) FROM artist me )",
58 $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
62 "( SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT me.id FROM cd me LIMIT ?) FROM artist me )",
72 { cd2 => $cdrs->search({ artist => { '>' => 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 artist > ?
80 [ { sqlt_datatype => 'integer', dbic_colname => 'artist' } => 20 ]
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 )"
105 { cd2 => $cdrs->search(
106 { artist => { '>' => 20 } },
110 { cd3 => $cdrs->search( { artist => { '<' => 40 } } )->as_query }
116 "( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track
118 (SELECT cd3.cdid, cd3.artist, cd3.title, cd3.year, cd3.genreid, cd3.single_track
120 (SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
121 FROM cd me WHERE artist < ?) cd3
122 WHERE artist > ?) cd2
124 [ { sqlt_datatype => 'integer', dbic_colname => 'artist' } => 40 ],
125 [ { dbic_colname => 'artist' } => 20 ], # no rsrc in outer manual from - hence no resolution
133 '=' => $cdrs->search(
134 { artistid => { '=' => \'me.artistid' } },
136 )->get_column('year')->max_rs->as_query,
140 "( 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) )",
149 { cd2 => $cdrs->search({ title => 'Thriller' })->as_query },
153 "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (
154 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE title = ?
157 [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'title' }
165 for my $i (0 .. $#tests) {
167 for my $p (1, 2) { # repeat everything twice, make sure we do not clobber search arguments
169 $t->{rs}->search ($t->{search}, $t->{attrs})->as_query,
171 sprintf 'Testcase %d, pass %d', $i+1, $p,