Commit | Line | Data |
f48dd03f |
1 | use strict;\r |
2 | use warnings;\r |
3 | \r |
4 | use Test::More;\r |
5 | use DBIx::Class::Storage::DBI;\r |
d8190011 |
6 | use lib qw(t/lib);\r |
7 | use DBICTest; # do not remove even though it is not used\r |
fd4cb60a |
8 | use DBIC::SqlMakerTest;\r |
f48dd03f |
9 | \r |
fd4cb60a |
10 | plan tests => 8;\r |
f48dd03f |
11 | \r |
6f4ddea1 |
12 | my $sa = new DBIx::Class::SQLAHacks;\r |
f48dd03f |
13 | $sa->limit_dialect( 'Top' );\r |
14 | \r |
fd4cb60a |
15 | sub test_order {\r |
16 | my $args = shift;\r |
17 | my $order_by = $args->{order_by};\r |
18 | my $expected_sql_order = $args->{expected_sql_order};\r |
19 | \r |
20 | my $query = $sa->select( 'foo', [qw{bar baz}], undef, {\r |
21 | order_by => $order_by,\r |
22 | }, 1, 3\r |
23 | );\r |
24 | is_same_sql(\r |
25 | $query,\r |
26 | "SELECT * FROM ( SELECT TOP 1 * FROM ( SELECT TOP 4 bar,baz FROM foo ORDER BY $expected_sql_order->[0] ) AS foo ORDER BY $expected_sql_order->[1] ) AS bar ORDER BY $expected_sql_order->[0]",\r |
27 | );\r |
28 | }\r |
29 | \r |
30 | test_order({ order_by => \'foo DESC' , expected_sql_order => [ 'foo DESC', 'foo ASC' ] });\r |
31 | test_order({ order_by => 'foo' , expected_sql_order => [ 'foo ASC', 'foo DESC'] });\r |
32 | test_order({ order_by => [ qw{ foo bar} ], expected_sql_order => [ 'foo ASC,bar ASC', 'foo DESC, bar DESC']});\r |
33 | test_order({ order_by => { -asc => 'foo' }, expected_sql_order => [ 'foo ASC', 'foo DESC' ] });\r |
34 | test_order({ order_by => { -desc => 'foo' }, expected_sql_order => [ 'foo DESC', 'foo ASC' ] });\r |
35 | \r |
36 | test_order({ order_by => ['foo', { -desc => 'bar' } ], expected_sql_order => [ 'foo ASC, bar DESC', 'foo DESC, bar ASC'] });\r |
37 | test_order({ order_by => {-asc => [qw{ foo bar }] }, expected_sql_order => ['foo ASC, bar ASC', 'foo DESC, bar DESC' ] });\r |
38 | test_order({ order_by =>\r |
39 | [\r |
40 | { -asc => 'foo' },\r |
41 | { -desc => [qw{bar}] },\r |
42 | { -asc => [qw{baz frew}]},\r |
43 | ],\r |
44 | expected_sql_order => ['foo ASC, bar DESC, baz ASC, frew ASC', 'foo DESC, bar ASC, baz DESC, frew DESC']\r |
45 | });\r |