7 use DBIC::SqlMakerTest;
9 my $schema = DBICTest->init_schema;
11 # Trick the sqlite DB to use Top limit emulation
12 # We could test all of this via $sq->$op directly,
13 # but some conditions needs a $rsrc
14 delete $schema->storage->_sql_maker->{_cached_syntax};
15 $schema->storage->_sql_maker->limit_dialect ('Top');
17 my $rs = $schema->resultset ('FourKeys')->search ({}, { rows => 1, offset => 3 });
22 my $req_order = $args->{order_req}
23 ? "ORDER BY $args->{order_req}"
28 $rs->search ({}, {order_by => $args->{order_by}})->as_query,
32 SELECT TOP 4 me.foo, me.bar, me.hello, me.goodbye, me.sensors, me.read_count FROM fourkeys me ORDER BY $args->{order_inner}
33 ) foo ORDER BY $args->{order_outer}
43 order_by => \ 'foo DESC',
44 order_req => 'foo DESC',
45 order_inner => 'foo DESC',
46 order_outer => 'foo ASC'
49 order_by => { -asc => 'foo' },
50 order_req => 'foo ASC',
51 order_inner => 'foo ASC',
52 order_outer => 'foo DESC',
57 order_inner => 'foo ASC',
58 order_outer => 'foo DESC',
61 order_by => [ qw{ foo bar} ],
62 order_req => 'foo, bar',
63 order_inner => 'foo ASC,bar ASC',
64 order_outer => 'foo DESC, bar DESC',
67 order_by => { -desc => 'foo' },
68 order_req => 'foo DESC',
69 order_inner => 'foo DESC',
70 order_outer => 'foo ASC',
73 order_by => ['foo', { -desc => 'bar' } ],
74 order_req => 'foo, bar DESC',
75 order_inner => 'foo ASC, bar DESC',
76 order_outer => 'foo DESC, bar ASC',
79 order_by => { -asc => [qw{ foo bar }] },
80 order_req => 'foo ASC, bar ASC',
81 order_inner => 'foo ASC, bar ASC',
82 order_outer => 'foo DESC, bar DESC',
87 { -desc => [qw{bar}] },
88 { -asc => [qw{hello sensors}]},
90 order_req => 'foo ASC, bar DESC, hello ASC, sensors ASC',
91 order_inner => 'foo ASC, bar DESC, hello ASC, sensors ASC',
92 order_outer => 'foo DESC, bar ASC, hello DESC, sensors DESC',
97 order_inner => 'foo ASC, bar ASC, hello ASC, goodbye ASC',
98 order_outer => 'foo DESC, bar DESC, hello DESC, goodbye DESC',
103 order_inner => 'foo ASC, bar ASC, hello ASC, goodbye ASC',
104 order_outer => 'foo DESC, bar DESC, hello DESC, goodbye DESC',
109 order_inner => 'foo ASC, bar ASC, hello ASC, goodbye ASC',
110 order_outer => 'foo DESC, bar DESC, hello DESC, goodbye DESC',
115 order_inner => 'foo ASC, bar ASC, hello ASC, goodbye ASC',
116 order_outer => 'foo DESC, bar DESC, hello DESC, goodbye DESC',
120 plan (tests => scalar @tests + 1);
122 test_order ($_) for @tests;
125 $rs->search ({}, { group_by => 'bar', order_by => 'bar' })->as_query,
131 SELECT TOP 4 me.foo, me.bar, me.hello, me.goodbye, me.sensors, me.read_count FROM fourkeys me GROUP BY bar ORDER BY bar ASC