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 $schema->is_executed_sql_bind(
22 sub { $schema->resultset('Artist')->find( Math::BigInt->new(42) ) },
25 'SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE me.artistid = ?',
26 [ { dbic_colname => "me.artistid", sqlt_datatype => "integer" }
27 => Math::BigInt->new(42) ],
32 my $rs = $schema->resultset('CD')->search({ -and => [
33 'me.artist' => { '!=', '666' },
34 'me.artist' => { '!=', \[ '?', [ _ne => 'bar' ] ] },
37 # bogus sql query to make sure bind composition happens properly
38 my $complex_rs = $rs->search({}, {
39 '+columns' => { cnt => $rs->count_rs->as_query },
40 '+select' => \[ 'me.artist + ?', [ _add => 1 ] ], # free select
41 group_by => ['me.cdid', \[ 'me.artist - ?', [ _sub => 2 ] ] ],
42 having => \[ 'me.artist < ?', [ _lt => 3 ] ],
43 order_by => \[ 'me.artist * ? ', [ _mu => 4 ] ],
50 $complex_rs->as_query,
52 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
53 (SELECT COUNT( * ) FROM cd me WHERE me.artist != ? AND me.artist != ?),
56 WHERE me.artist != ? AND me.artist != ?
57 GROUP BY me.cdid, me.artist - ?
59 ORDER BY me.artist * ?
63 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
64 [ { dbic_colname => '_ne' } => 'bar' ],
65 [ { dbic_colname => '_add' } => 1 ],
66 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
67 [ { dbic_colname => '_ne' } => 'bar' ],
68 [ { dbic_colname => '_sub' } => 2 ],
69 [ { dbic_colname => '_lt' } => 3 ],
70 [ { dbic_colname => '_mu' } => 4 ],
78 # see if we get anything back at all
79 isa_ok ($complex_rs->next, 'DBIx::Class::Row');
81 # Make sure that the bind shorthand syntax translation is accurate (and doesn't error)
84 [ { dbic_colname => '_sub' } => 2 ],
85 '[ $name => $val ] === [ { dbic_colname => $name }, $val ]',
89 [ { dbic_colname => 'artist', sqlt_datatype => 'integer' } => 2 ],
90 'resolution of known column during [ $name => $val ] === [ { dbic_colname => $name }, $val ]',
94 [ { sqlt_datatype => 'number' } => 2 ],
95 '[ \$dt => $val ] === [ { sqlt_datatype => $dt }, $val ]',
100 '[ {} => $val ] === [ {}, $val ]',
105 '[ undef, $val ] === [ {}, $val ]',
110 '$val === [ {}, $val ]',
114 Math::BigInt->new(42),
115 [ {} => Math::BigInt->new(42) ],
116 'stringifyable $object === [ {}, $object ]',
131 [ {} => [ {}, 2, 3 ] ],
136 [ {} => bless( {}, 'Foo') ],
140 [ {}, bless( {}, 'Foo') ],
141 [ {}, bless( {}, 'Foo') ],
145 sub shorthand_check {
146 my ($bind_shorthand, $bind_expected, $testname) = @_;
148 local $Test::Builder::Level = $Test::Builder::Level + 1;
151 $schema->resultset('CD')->search({}, {
152 columns => [qw(cdid artist)],
153 group_by => ['cdid', \[ 'artist - ?', $bind_shorthand ] ],
156 SELECT me.cdid, me.artist
158 GROUP BY cdid, artist - ?