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