10 use DBIC::SqlMakerTest;
11 use DBIx::Class::SQLMaker::LimitDialects;
13 my ($ROWS, $OFFSET) = (
14 DBIx::Class::SQLMaker::LimitDialects->__rows_bindtype,
15 DBIx::Class::SQLMaker::LimitDialects->__offset_bindtype,
18 my $schema = DBICTest->init_schema();
20 my $rs = $schema->resultset('CD')->search({ -and => [
21 'me.artist' => { '!=', '666' },
22 'me.artist' => { '!=', \[ '?', [ _ne => 'bar' ] ] },
25 # bogus sql query to make sure bind composition happens properly
26 my $complex_rs = $rs->search({}, {
27 '+columns' => { cnt => $rs->count_rs->as_query },
28 '+select' => \[ 'me.artist + ?', [ _add => 1 ] ], # free select
29 group_by => ['me.cdid', \[ 'me.artist - ?', [ _sub => 2 ] ] ],
30 having => \[ 'me.artist < ?', [ _lt => 3 ] ],
31 order_by => \[ 'me.artist * ? ', [ _mu => 4 ] ],
38 $complex_rs->as_query,
40 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
41 (SELECT COUNT( * ) FROM cd me WHERE me.artist != ? AND me.artist != ?),
44 WHERE me.artist != ? AND me.artist != ?
45 GROUP BY me.cdid, me.artist - ?
47 ORDER BY me.artist * ?
51 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
52 [ { dbic_colname => '_ne' } => 'bar' ],
53 [ { dbic_colname => '_add' } => 1 ],
54 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
55 [ { dbic_colname => '_ne' } => 'bar' ],
56 [ { dbic_colname => '_sub' } => 2 ],
57 [ { dbic_colname => '_lt' } => 3 ],
58 [ { dbic_colname => '_mu' } => 4 ],
66 # see if we get anything back at all
67 isa_ok ($complex_rs->next, 'DBIx::Class::Row');
69 # Make sure that the bind shorthand syntax translation is accurate (and doesn't error)
72 [ { dbic_colname => '_sub' } => 2 ],
73 '[ $name => $val ] === [ { dbic_colname => $name }, $val ]',
77 [ { dbic_colname => 'artist', sqlt_datatype => 'integer' } => 2 ],
78 'resolution of known column during [ $name => $val ] === [ { dbic_colname => $name }, $val ]',
82 [ { sqlt_datatype => 'number' } => 2 ],
83 '[ \$dt => $val ] === [ { sqlt_datatype => $dt }, $val ]',
88 '[ {} => $val ] === [ {}, $val ]',
93 '[ undef, $val ] === [ {}, $val ]',
98 '$val === [ {}, $val ]',
102 Math::BigInt->new(42),
103 [ {} => Math::BigInt->new(42) ],
104 'stringifyable $object === [ {}, $object ]',
112 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Q[ 2 ]!,
113 'exception on bare array bindvalue';
120 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Q[ 2 ]!,
121 'exception on untyped array bindvalue';
128 } qr !You must supply a datatype/bindtype .+ for non-scalar value \[ 'HASH\(\w+\)', 2, 3 \]!,
129 'exception on bare multielement array bindvalue';
136 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Qbless( {}, 'Foo' )!,
137 'exception on bare object';
141 [ {}, bless( {}, 'Foo') ],
144 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Qbless( {}, 'Foo' )!,
145 'exception on untyped object';
148 sub shorthand_check {
149 my ($bind_shorthand, $bind_expected, $testname) = @_;
151 local $Test::Builder::Level = $Test::Builder::Level + 1;
154 $schema->resultset('CD')->search({}, {
155 columns => [qw(cdid artist)],
156 group_by => ['cdid', \[ 'artist - ?', $bind_shorthand ] ],
159 SELECT me.cdid, me.artist
161 GROUP BY cdid, artist - ?