Factor out bindattr resolver and tighten code a bit
[dbsrgits/DBIx-Class.git] / t / sqlmaker / bind_transport.t
CommitLineData
0542ec57 1use strict;
2use warnings;
3use Test::More;
4
5use lib qw(t/lib);
6use DBICTest;
7use DBIC::SqlMakerTest;
fcb7fcbb 8use DBIx::Class::SQLMaker::LimitDialects;
9
10my ($ROWS, $OFFSET) = (
11 DBIx::Class::SQLMaker::LimitDialects->__rows_bindtype,
12 DBIx::Class::SQLMaker::LimitDialects->__offset_bindtype,
13);
0542ec57 14
15my $schema = DBICTest->init_schema();
16
0542ec57 17my $rs = $schema->resultset('CD')->search({ -and => [
0e773352 18 'me.artist' => { '!=', '666' },
19 'me.artist' => { '!=', \[ '?', [ _ne => 'bar' ] ] },
0542ec57 20]});
21
22# bogus sql query to make sure bind composition happens properly
23my $complex_rs = $rs->search({}, {
24 '+columns' => { cnt => $rs->count_rs->as_query },
25 '+select' => \[ 'me.artist + ?', [ _add => 1 ] ], # free select
26 group_by => ['me.cdid', \[ 'me.artist - ?', [ _sub => 2 ] ] ],
27 having => \[ 'me.artist < ?', [ _lt => 3 ] ],
28 order_by => \[ 'me.artist * ? ', [ _mu => 4 ] ],
29 rows => 1,
30 page => 3,
31});
32
33for (1,2) {
34 is_same_sql_bind (
35 $complex_rs->as_query,
36 '(
37 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track,
38 (SELECT COUNT( * ) FROM cd me WHERE me.artist != ? AND me.artist != ?),
39 me.artist + ?
40 FROM cd me
41 WHERE me.artist != ? AND me.artist != ?
42 GROUP BY me.cdid, me.artist - ?
43 HAVING me.artist < ?
44 ORDER BY me.artist * ?
fcb7fcbb 45 LIMIT ? OFFSET ?
0542ec57 46 )',
47 [
fcb7fcbb 48 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
0e773352 49 [ { dbic_colname => '_ne' } => 'bar' ],
50 [ { dbic_colname => '_add' } => 1 ],
fcb7fcbb 51 [ { sqlt_datatype => 'integer', dbic_colname => 'me.artist' } => 666 ],
0e773352 52 [ { dbic_colname => '_ne' } => 'bar' ],
53 [ { dbic_colname => '_sub' } => 2 ],
54 [ { dbic_colname => '_lt' } => 3 ],
55 [ { dbic_colname => '_mu' } => 4 ],
fcb7fcbb 56 [ $ROWS => 1 ],
57 [ $OFFSET => 2 ],
0542ec57 58 ],
59 'Correct crazy sql',
60 );
61}
62
63# see if we get anything back at all
64isa_ok ($complex_rs->next, 'DBIx::Class::Row');
65
66done_testing;