1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
11 use DBICTest ':DiffSQL';
12 use DBIx::Class::SQLMaker::LimitDialects;
14 my ($ROWS, $OFFSET) = (
15 DBIx::Class::SQLMaker::LimitDialects->__rows_bindtype,
16 DBIx::Class::SQLMaker::LimitDialects->__offset_bindtype,
19 my $schema = DBICTest->init_schema();
21 my $rs = $schema->resultset('CD')->search({ -and => [
22 'me.artist' => { '!=', '666' },
23 'me.artist' => { '!=', \[ '?', [ _ne => 'bar' ] ] },
26 # bogus sql query to make sure bind composition happens properly
27 my $complex_rs = $rs->search({}, {
28 '+columns' => { cnt => $rs->count_rs->as_query },
29 '+select' => \[ 'me.artist + ?', [ _add => 1 ] ], # free select
30 group_by => ['me.cdid', \[ 'me.artist - ?', [ _sub => 2 ] ] ],
31 having => \[ 'me.artist < ?', [ _lt => 3 ] ],
32 order_by => \[ 'me.artist * ? ', [ _mu => 4 ] ],
39 $complex_rs->as_query,
41 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
42 (SELECT COUNT( * ) FROM cd me WHERE me.artist != ? AND me.artist != ?),
45 WHERE me.artist != ? AND me.artist != ?
46 GROUP BY me.cdid, me.artist - ?
48 ORDER BY me.artist * ?
52 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
53 [ { dbic_colname => '_ne' } => 'bar' ],
54 [ { dbic_colname => '_add' } => 1 ],
55 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
56 [ { dbic_colname => '_ne' } => 'bar' ],
57 [ { dbic_colname => '_sub' } => 2 ],
58 [ { dbic_colname => '_lt' } => 3 ],
59 [ { dbic_colname => '_mu' } => 4 ],
67 # see if we get anything back at all
68 isa_ok ($complex_rs->next, 'DBIx::Class::Row');
70 # Make sure that the bind shorthand syntax translation is accurate (and doesn't error)
73 [ { dbic_colname => '_sub' } => 2 ],
74 '[ $name => $val ] === [ { dbic_colname => $name }, $val ]',
78 [ { dbic_colname => 'artist', sqlt_datatype => 'integer' } => 2 ],
79 'resolution of known column during [ $name => $val ] === [ { dbic_colname => $name }, $val ]',
83 [ { sqlt_datatype => 'number' } => 2 ],
84 '[ \$dt => $val ] === [ { sqlt_datatype => $dt }, $val ]',
89 '[ {} => $val ] === [ {}, $val ]',
94 '[ undef, $val ] === [ {}, $val ]',
99 '$val === [ {}, $val ]',
103 Math::BigInt->new(42),
104 [ {} => Math::BigInt->new(42) ],
105 'stringifyable $object === [ {}, $object ]',
120 [ {} => [ {}, 2, 3 ] ],
125 [ {} => bless( {}, 'Foo') ],
129 [ {}, bless( {}, 'Foo') ],
130 [ {}, bless( {}, 'Foo') ],
134 sub shorthand_check {
135 my ($bind_shorthand, $bind_expected, $testname) = @_;
137 local $Test::Builder::Level = $Test::Builder::Level + 1;
140 $schema->resultset('CD')->search({}, {
141 columns => [qw(cdid artist)],
142 group_by => ['cdid', \[ 'artist - ?', $bind_shorthand ] ],
145 SELECT me.cdid, me.artist
147 GROUP BY cdid, artist - ?