Fix bind transport for group_by (this code is so fucking ugly...)
[dbsrgits/DBIx-Class.git] / t / sqlmaker / bind_transport.t
CommitLineData
0542ec57 1use strict;
2use warnings;
3use Test::More;
4
5use lib qw(t/lib);
6use DBICTest;
7use DBIC::SqlMakerTest;
8
9my $schema = DBICTest->init_schema();
10
11my $ne_bind = [ _ne => 'bar' ];
12my $rs = $schema->resultset('CD')->search({ -and => [
13 'me.artist' => { '!=', 'foo' },
14 'me.artist' => { '!=', \[ '?', $ne_bind ] },
15]});
16
17# bogus sql query to make sure bind composition happens properly
18my $complex_rs = $rs->search({}, {
19 '+columns' => { cnt => $rs->count_rs->as_query },
20 '+select' => \[ 'me.artist + ?', [ _add => 1 ] ], # free select
21 group_by => ['me.cdid', \[ 'me.artist - ?', [ _sub => 2 ] ] ],
22 having => \[ 'me.artist < ?', [ _lt => 3 ] ],
23 order_by => \[ 'me.artist * ? ', [ _mu => 4 ] ],
24 rows => 1,
25 page => 3,
26});
27
28for (1,2) {
29 is_same_sql_bind (
30 $complex_rs->as_query,
31 '(
32 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
33 (SELECT COUNT( * ) FROM cd me WHERE me.artist != ? AND me.artist != ?),
34 me.artist + ?
35 FROM cd me
36 WHERE me.artist != ? AND me.artist != ?
37 GROUP BY me.cdid, me.artist - ?
38 HAVING me.artist < ?
39 ORDER BY me.artist * ?
40 LIMIT 1 OFFSET 2
41 )',
42 [
43 [ 'me.artist' => 'foo' ],
44 $ne_bind,
45 [ _add => 1 ],
46 [ 'me.artist' => 'foo' ],
47 $ne_bind,
48 [ _sub => 2 ],
49 [ _lt => 3 ],
50 [ _mu => 4 ],
51 ],
52 'Correct crazy sql',
53 );
54}
55
56# see if we get anything back at all
57isa_ok ($complex_rs->next, 'DBIx::Class::Row');
58
59done_testing;