Parameterize pagination
[dbsrgits/DBIx-Class.git] / t / sqlmaker / limit_dialects / rownum.t
CommitLineData
327368bc 1use strict;
2use warnings;
3
4use Test::More;
5
6use lib qw(t/lib);
7use DBICTest;
8use DBIC::SqlMakerTest;
fcb7fcbb 9use DBIx::Class::SQLMaker::LimitDialects;
10
11my ($TOTAL, $OFFSET) = (
12 DBIx::Class::SQLMaker::LimitDialects->__total_bindtype,
13 DBIx::Class::SQLMaker::LimitDialects->__offset_bindtype,
14);
327368bc 15
16my $s = DBICTest->init_schema (no_deploy => 1, );
17$s->storage->sql_maker->limit_dialect ('RowNum');
18
19my $rs = $s->resultset ('CD');
20
21is_same_sql_bind (
22 $rs->search ({}, { rows => 1, offset => 3,columns => [
23 { id => 'foo.id' },
24 { 'bar.id' => 'bar.id' },
25 { bleh => \ 'TO_CHAR (foo.womble, "blah")' },
26 ]})->as_query,
d9672fb9 27 '(
28 SELECT id, bar__id, bleh
327368bc 29 FROM (
30 SELECT id, bar__id, bleh, ROWNUM rownum__index
31 FROM (
32 SELECT foo.id AS id, bar.id AS bar__id, TO_CHAR(foo.womble, "blah") AS bleh
33 FROM cd me
34 ) me
fcb7fcbb 35 WHERE ROWNUM <= ?
327368bc 36 ) me
fcb7fcbb 37 WHERE rownum__index >= ?
327368bc 38 )',
fcb7fcbb 39 [
40 [ $TOTAL => 4 ],
41 [ $OFFSET => 4 ],
42 ],
327368bc 43 'Rownum subsel aliasing works correctly'
44);
45
f8583f8f 46is_same_sql_bind (
d9672fb9 47 $rs->search ({}, { rows => 2, offset => 3,columns => [
f8583f8f 48 { id => 'foo.id' },
49 { 'ends_with_me.id' => 'ends_with_me.id' },
50 ]})->as_query,
51 '(SELECT id, ends_with_me__id
52 FROM (
53 SELECT id, ends_with_me__id, ROWNUM rownum__index
54 FROM (
55 SELECT foo.id AS id, ends_with_me.id AS ends_with_me__id
56 FROM cd me
57 ) me
fcb7fcbb 58 WHERE ROWNUM <= ?
f8583f8f 59 ) me
fcb7fcbb 60 WHERE rownum__index >= ?
f8583f8f 61 )',
fcb7fcbb 62 [
63 [ $TOTAL => 5 ],
64 [ $OFFSET => 4 ],
65 ],
f8583f8f 66 'Rownum subsel aliasing works correctly'
67);
68
d7632687 69{
70 $rs = $s->resultset('Artist')->search({}, {
71 columns => 'name',
72 offset => 1,
73 order_by => 'name',
74 });
75 local $rs->result_source->{name} = "weird \n newline/multi \t \t space containing \n table";
76
77 like (
78 ${$rs->as_query}->[0],
79 qr| weird \s \n \s newline/multi \s \t \s \t \s space \s containing \s \n \s table|x,
80 'Newlines/spaces preserved in final sql',
81 );
82}
83
84
327368bc 85done_testing;