Commit | Line | Data |
0c033974 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
a2368d30 |
5 | use Test::Exception; |
a17640f1 |
6 | use Data::Dumper::Concise; |
0c033974 |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | use DBIC::SqlMakerTest; |
10 | |
11 | my $schema = DBICTest->init_schema; |
12 | |
13 | my $rs = $schema->resultset('FourKeys'); |
14 | |
15 | sub test_order { |
a2368d30 |
16 | |
17 | TODO: { |
0c033974 |
18 | my $args = shift; |
19 | |
a2368d30 |
20 | local $TODO = "Not implemented" if $args->{todo}; |
0c033974 |
21 | |
a2368d30 |
22 | lives_ok { |
23 | is_same_sql_bind( |
0c033974 |
24 | $rs->search( |
25 | { foo => 'bar' }, |
26 | { |
27 | order_by => $args->{order_by}, |
28 | having => |
a17640f1 |
29 | [ { read_count => { '>' => 5 } }, \[ 'read_count < ?', [ read_count => 8 ] ] ] |
0c033974 |
30 | } |
31 | )->as_query, |
32 | "( |
33 | SELECT me.foo, me.bar, me.hello, me.goodbye, me.sensors, me.read_count |
34 | FROM fourkeys me |
35 | WHERE ( foo = ? ) |
36 | HAVING read_count > ? OR read_count < ? |
a2368d30 |
37 | ORDER BY $args->{order_req} |
0c033974 |
38 | )", |
39 | [ |
0e773352 |
40 | [ { sqlt_datatype => 'integer', dbic_colname => 'foo' } |
41 | => 'bar' ], |
42 | [ { sqlt_datatype => 'int', dbic_colname => 'read_count' } |
43 | => 5 ], |
44 | [ { sqlt_datatype => 'int', dbic_colname => 'read_count' } |
45 | => 8 ], |
a2368d30 |
46 | $args->{bind} |
0e773352 |
47 | ? map { [ { dbic_colname => $_->[0] } => $_->[1] ] } @{ $args->{bind} } |
a2368d30 |
48 | : () |
0c033974 |
49 | ], |
a17640f1 |
50 | ) || diag Dumper $args->{order_by}; |
a2368d30 |
51 | }; |
a2368d30 |
52 | } |
0c033974 |
53 | } |
54 | |
55 | my @tests = ( |
56 | { |
57 | order_by => \'foo DESC', |
58 | order_req => 'foo DESC', |
59 | bind => [], |
60 | }, |
61 | { |
62 | order_by => { -asc => 'foo' }, |
63 | order_req => 'foo ASC', |
64 | bind => [], |
65 | }, |
66 | { |
a17640f1 |
67 | order_by => { -desc => \[ 'colA LIKE ?', [ colA => 'test' ] ] }, |
0c033974 |
68 | order_req => 'colA LIKE ? DESC', |
a17640f1 |
69 | bind => [ [ colA => 'test' ] ], |
0c033974 |
70 | }, |
71 | { |
a17640f1 |
72 | order_by => \[ 'colA LIKE ? DESC', [ colA => 'test' ] ], |
0c033974 |
73 | order_req => 'colA LIKE ? DESC', |
a17640f1 |
74 | bind => [ [ colA => 'test' ] ], |
0c033974 |
75 | }, |
76 | { |
77 | order_by => [ |
78 | { -asc => \['colA'] }, |
a17640f1 |
79 | { -desc => \[ 'colB LIKE ?', [ colB => 'test' ] ] }, |
80 | { -asc => \[ 'colC LIKE ?', [ colC => 'tost' ] ] }, |
0c033974 |
81 | ], |
82 | order_req => 'colA ASC, colB LIKE ? DESC, colC LIKE ? ASC', |
a17640f1 |
83 | bind => [ [ colB => 'test' ], [ colC => 'tost' ] ], |
0c033974 |
84 | }, |
a2368d30 |
85 | { |
a17640f1 |
86 | todo => 1, |
0c033974 |
87 | order_by => [ |
88 | { -asc => 'colA' }, |
89 | { -desc => { colB => { 'LIKE' => 'test' } } }, |
90 | { -asc => { colC => { 'LIKE' => 'tost' } } } |
91 | ], |
92 | order_req => 'colA ASC, colB LIKE ? DESC, colC LIKE ? ASC', |
a17640f1 |
93 | bind => [ [ colB => 'test' ], [ colC => 'tost' ] ], |
0c033974 |
94 | }, |
95 | { |
a17640f1 |
96 | todo => 1, |
0c033974 |
97 | order_by => { -desc => { colA => { LIKE => 'test' } } }, |
98 | order_req => 'colA LIKE ? DESC', |
a17640f1 |
99 | bind => [ [ colA => 'test' ] ], |
0c033974 |
100 | }, |
101 | ); |
102 | |
0c033974 |
103 | test_order($_) for @tests; |
22912b45 |
104 | |
a17640f1 |
105 | done_testing; |