Failing test about warnings triggered in SQLA::Limit when using a subquery
[dbsrgits/DBIx-Class-Historic.git] / t / 42toplimit.t
CommitLineData
65c2b042 1use strict;
2use warnings;
3
4use Test::More;
5use DBIx::Class::Storage::DBI;
6use lib qw(t/lib);
7use DBICTest; # do not remove even though it is not used
8use DBIC::SqlMakerTest;
9
6a67b557 10plan tests => 10;
65c2b042 11
12my $sa = new DBIx::Class::SQLAHacks;
13$sa->limit_dialect( 'Top' );
14
15sub test_order {
16 my $args = shift;
17 my $order_by = $args->{order_by};
18 my $expected_sql_order = $args->{expected_sql_order};
19
20 my $query = $sa->select( 'foo', [qw{bar baz}], undef, {
21 order_by => $order_by,
22 }, 1, 3
23 );
24 is_same_sql(
25 $query,
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]",
27 );
28}
29
30 test_order({ order_by => \'foo DESC' , expected_sql_order => [ 'foo DESC', 'foo ASC' ] });
31 test_order({ order_by => 'foo' , expected_sql_order => [ 'foo ASC', 'foo DESC'] });
32 test_order({ order_by => [ qw{ foo bar} ], expected_sql_order => [ 'foo ASC,bar ASC', 'foo DESC, bar DESC']});
33 test_order({ order_by => { -asc => 'foo' }, expected_sql_order => [ 'foo ASC', 'foo DESC' ] });
34 test_order({ order_by => { -desc => 'foo' }, expected_sql_order => [ 'foo DESC', 'foo ASC' ] });
35
36 test_order({ order_by => ['foo', { -desc => 'bar' } ], expected_sql_order => [ 'foo ASC, bar DESC', 'foo DESC, bar ASC'] });
37 test_order({ order_by => {-asc => [qw{ foo bar }] }, expected_sql_order => ['foo ASC, bar ASC', 'foo DESC, bar DESC' ] });
38 test_order({ order_by =>
39 [
40 { -asc => 'foo' },
41 { -desc => [qw{bar}] },
42 { -asc => [qw{baz frew}]},
43 ],
44 expected_sql_order => ['foo ASC, bar DESC, baz ASC, frew ASC', 'foo DESC, bar ASC, baz DESC, frew DESC']
45 });
6a67b557 46
47{
48
49 my @w;
50 local $SIG{__WARN__} = sub { $_[0] =~ /Use of uninitialized value/ ? push @w, @_ : warn @_ };
51 my $subquery = $sa->select( [{ subq => \['(SELECT * FROM foo)'] }], [qw{bar baz}], undef, undef, 1, 3);
52 is_same_sql(
53 $subquery,
54 "SELECT * FROM ( SELECT TOP 1 * FROM ( SELECT TOP 4 bar,baz FROM (SELECT * FROM foo) ) AS foo) AS bar",
55 );
56
57 is (@w, 0, 'No warnings on limit with subquery')
58 || diag join ("\n", @w);
59}