8 local $TODO = 'Temporarily todo-ed for dq2eb';
12 use DBIC::SqlMakerTest;
13 use DBIx::Class::SQLMaker::LimitDialects;
15 my ($ROWS, $OFFSET) = (
16 DBIx::Class::SQLMaker::LimitDialects->__rows_bindtype,
17 DBIx::Class::SQLMaker::LimitDialects->__offset_bindtype,
20 my $schema = DBICTest->init_schema();
22 my $rs = $schema->resultset('CD')->search({ -and => [
23 'me.artist' => { '!=', '666' },
24 'me.artist' => { '!=', \[ '?', [ _ne => 'bar' ] ] },
27 # bogus sql query to make sure bind composition happens properly
28 my $complex_rs = $rs->search({}, {
29 '+columns' => { cnt => $rs->count_rs->as_query },
30 '+select' => \[ 'me.artist + ?', [ _add => 1 ] ], # free select
31 group_by => ['me.cdid', \[ 'me.artist - ?', [ _sub => 2 ] ] ],
32 having => \[ 'me.artist < ?', [ _lt => 3 ] ],
33 order_by => \[ 'me.artist * ? ', [ _mu => 4 ] ],
40 $complex_rs->as_query,
42 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
43 (SELECT COUNT( * ) FROM cd me WHERE me.artist != ? AND me.artist != ?),
46 WHERE me.artist != ? AND me.artist != ?
47 GROUP BY me.cdid, me.artist - ?
49 ORDER BY me.artist * ?
53 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
54 [ { dbic_colname => '_ne' } => 'bar' ],
55 [ { dbic_colname => '_add' } => 1 ],
56 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
57 [ { dbic_colname => '_ne' } => 'bar' ],
58 [ { dbic_colname => '_sub' } => 2 ],
59 [ { dbic_colname => '_lt' } => 3 ],
60 [ { dbic_colname => '_mu' } => 4 ],
68 # see if we get anything back at all
69 isa_ok ($complex_rs->next, 'DBIx::Class::Row');
71 # Make sure that the bind shorthand syntax translation is accurate (and doesn't error)
74 [ { dbic_colname => '_sub' } => 2 ],
75 '[ $name => $val ] === [ { dbic_colname => $name }, $val ]',
79 [ { dbic_colname => 'artist', sqlt_datatype => 'integer' } => 2 ],
80 'resolution of known column during [ $name => $val ] === [ { dbic_colname => $name }, $val ]',
84 [ { sqlt_datatype => 'number' } => 2 ],
85 '[ \$dt => $val ] === [ { sqlt_datatype => $dt }, $val ]',
90 '[ {} => $val ] === [ {}, $val ]',
95 '[ undef, $val ] === [ {}, $val ]',
100 '$val === [ {}, $val ]',
104 Math::BigInt->new(42),
105 [ {} => Math::BigInt->new(42) ],
106 'stringifyable $object === [ {}, $object ]',
114 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Q[ 2 ]!,
115 'exception on bare array bindvalue';
122 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Q[ 2 ]!,
123 'exception on untyped array bindvalue';
130 } qr !You must supply a datatype/bindtype .+ for non-scalar value \[ 'HASH\(\w+\)', 2, 3 \]!,
131 'exception on bare multielement array bindvalue';
138 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Qbless( {}, 'Foo' )!,
139 'exception on bare object';
143 [ {}, bless( {}, 'Foo') ],
146 } qr !You must supply a datatype/bindtype .+ for non-scalar value \Qbless( {}, 'Foo' )!,
147 'exception on untyped object';
150 sub shorthand_check {
151 my ($bind_shorthand, $bind_expected, $testname) = @_;
153 local $Test::Builder::Level = $Test::Builder::Level + 1;
156 $schema->resultset('CD')->search({}, {
157 columns => [qw(cdid artist)],
158 group_by => ['cdid', \[ 'artist - ?', $bind_shorthand ] ],
161 SELECT me.cdid, me.artist
163 GROUP BY cdid, artist - ?