7 use DBIC::SqlMakerTest;
9 my $schema = DBICTest->init_schema(
12 storage_type => '::DBI::MSSQL',
15 my $rs = $schema->resultset ('BooksInLibrary')->search ({}, { prefetch => 'owner', rows => 1, offset => 3 });
17 sub default_test_order {
20 $rs->search ({}, {order_by => $order_by})->as_query,
21 "(SELECT me__id, me__source, me__owner, me__title, me__price, owner__id, owner__name FROM
23 SELECT Q1.*, ROW_NUMBER() OVER( ) AS ROW_NUM FROM (
24 SELECT me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name
25 FROM books me JOIN owners owner ON owner.id = me.owner WHERE ( source = ? )
28 WHERE ROW_NUM BETWEEN 4 and 4
30 [ [ source => 'Library' ] ],
37 my $req_order = $args->{order_req}
38 ? "ORDER BY $args->{order_req}"
43 $rs->search ({}, {order_by => $args->{order_by}})->as_query,
44 "(SELECT me__id, me__source, me__owner, me__title, me__price, owner__id, owner__name FROM
46 SELECT Q1.*, ROW_NUMBER() OVER( ) AS ROW_NUM FROM (
47 SELECT me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name
48 FROM books me JOIN owners owner ON owner.id = me.owner WHERE ( source = ? )
52 WHERE ROW_NUM BETWEEN 4 and 4
54 [ [ source => 'Library' ] ],
60 order_by => \'foo DESC',
61 order_req => 'foo DESC',
62 order_inner => 'foo DESC',
63 order_outer => 'foo ASC'
66 order_by => { -asc => 'foo' },
67 order_req => 'foo ASC',
68 order_inner => 'foo ASC',
69 order_outer => 'foo DESC',
74 order_inner => 'foo ASC',
75 order_outer => 'foo DESC',
78 order_by => [ qw{ foo bar} ],
79 order_req => 'foo, bar',
80 order_inner => 'foo ASC,bar ASC',
81 order_outer => 'foo DESC, bar DESC',
84 order_by => { -desc => 'foo' },
85 order_req => 'foo DESC',
86 order_inner => 'foo DESC',
87 order_outer => 'foo ASC',
90 order_by => ['foo', { -desc => 'bar' } ],
91 order_req => 'foo, bar DESC',
92 order_inner => 'foo ASC, bar DESC',
93 order_outer => 'foo DESC, bar ASC',
96 order_by => { -asc => [qw{ foo bar }] },
97 order_req => 'foo ASC, bar ASC',
98 order_inner => 'foo ASC, bar ASC',
99 order_outer => 'foo DESC, bar DESC',
104 { -desc => [qw{bar}] },
105 { -asc => [qw{hello sensors}]},
107 order_req => 'foo ASC, bar DESC, hello ASC, sensors ASC',
108 order_inner => 'foo ASC, bar DESC, hello ASC, sensors ASC',
109 order_outer => 'foo DESC, bar ASC, hello DESC, sensors DESC',
113 my @default_tests = ( undef, '', {}, [] );
115 plan (tests => scalar @tests + scalar @default_tests + 1);
117 test_order ($_) for @tests;
118 default_test_order ($_) for @default_tests;
122 $rs->search ({}, { group_by => 'title', order_by => 'title' })->as_query,
124 me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name FROM
126 id, source, owner, title, price FROM
128 TOP 1 id, source, owner, title, price FROM
130 TOP 4 me.id, me.source, me.owner, me.title, me.price FROM
132 owners owner ON owner.id = me.owner
141 owners owner ON owner.id = me.owner WHERE
144 [ [ source => 'Library' ], [ source => 'Library' ] ],