9 use DBICTest ':DiffSQL';
10 use DBIx::Class::SQLMaker::LimitDialects;
12 my ($ROWS, $OFFSET) = (
13 DBIx::Class::SQLMaker::LimitDialects->__rows_bindtype,
14 DBIx::Class::SQLMaker::LimitDialects->__offset_bindtype,
17 my $schema = DBICTest->init_schema();
19 my $rs = $schema->resultset('CD')->search({ -and => [
20 'me.artist' => { '!=', '666' },
21 'me.artist' => { '!=', \[ '?', [ _ne => 'bar' ] ] },
24 # bogus sql query to make sure bind composition happens properly
25 my $complex_rs = $rs->search({}, {
26 '+columns' => { cnt => $rs->count_rs->as_query },
27 '+select' => \[ 'me.artist + ?', [ _add => 1 ] ], # free select
28 group_by => ['me.cdid', \[ 'me.artist - ?', [ _sub => 2 ] ] ],
29 having => \[ 'me.artist < ?', [ _lt => 3 ] ],
30 order_by => \[ 'me.artist * ? ', [ _mu => 4 ] ],
37 $complex_rs->as_query,
39 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
40 (SELECT COUNT( * ) FROM cd me WHERE me.artist != ? AND me.artist != ?),
43 WHERE me.artist != ? AND me.artist != ?
44 GROUP BY me.cdid, me.artist - ?
46 ORDER BY me.artist * ?
50 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
51 [ { dbic_colname => '_ne' } => 'bar' ],
52 [ { dbic_colname => '_add' } => 1 ],
53 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
54 [ { dbic_colname => '_ne' } => 'bar' ],
55 [ { dbic_colname => '_sub' } => 2 ],
56 [ { dbic_colname => '_lt' } => 3 ],
57 [ { dbic_colname => '_mu' } => 4 ],
65 # see if we get anything back at all
66 isa_ok ($complex_rs->next, 'DBIx::Class::Row');
68 # Make sure that the bind shorthand syntax translation is accurate (and doesn't error)
71 [ { dbic_colname => '_sub' } => 2 ],
72 '[ $name => $val ] === [ { dbic_colname => $name }, $val ]',
76 [ { dbic_colname => 'artist', sqlt_datatype => 'integer' } => 2 ],
77 'resolution of known column during [ $name => $val ] === [ { dbic_colname => $name }, $val ]',
81 [ { sqlt_datatype => 'number' } => 2 ],
82 '[ \$dt => $val ] === [ { sqlt_datatype => $dt }, $val ]',
87 '[ {} => $val ] === [ {}, $val ]',
92 '[ undef, $val ] === [ {}, $val ]',
97 '$val === [ {}, $val ]',
101 Math::BigInt->new(42),
102 [ {} => Math::BigInt->new(42) ],
103 'stringifyable $object === [ {}, $object ]',
111 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Q[ 2 ]!,
112 'exception on bare array bindvalue';
119 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Q[ 2 ]!,
120 'exception on untyped array bindvalue';
127 } qr !You must supply a datatype/bindtype .+ for non-scalar value \[ 'HASH\(\w+\)', 2, 3 \]!,
128 'exception on bare multielement array bindvalue';
135 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Qbless( {}, 'Foo' )!,
136 'exception on bare object';
140 [ {}, bless( {}, 'Foo') ],
143 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Qbless( {}, 'Foo' )!,
144 'exception on untyped object';
147 sub shorthand_check {
148 my ($bind_shorthand, $bind_expected, $testname) = @_;
150 local $Test::Builder::Level = $Test::Builder::Level + 1;
153 $schema->resultset('CD')->search({}, {
154 columns => [qw(cdid artist)],
155 group_by => ['cdid', \[ 'artist - ?', $bind_shorthand ] ],
158 SELECT me.cdid, me.artist
160 GROUP BY cdid, artist - ?