Commit | Line | Data |
a5f843e3 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | use DBIC::SqlMakerTest; |
8 | |
9 | my $schema = DBICTest->init_schema; |
10 | |
a5f843e3 |
11 | $schema->storage->_sql_maker->limit_dialect ('RowNumberOver'); |
12 | |
41eac664 |
13 | my $rs_selectas_col = $schema->resultset ('BooksInLibrary')->search ({}, { |
14 | '+select' => ['owner.name'], |
15 | '+as' => ['owner.name'], |
16 | join => 'owner', |
17 | rows => 1, |
18 | }); |
a5f843e3 |
19 | |
41eac664 |
20 | is_same_sql_bind( |
21 | $rs_selectas_col->as_query, |
22 | '( |
760545fa |
23 | SELECT id, source, owner, title, price, |
24 | owner__name |
41eac664 |
25 | FROM ( |
760545fa |
26 | SELECT id, source, owner, title, price, |
27 | owner__name, |
41eac664 |
28 | ROW_NUMBER() OVER( ) AS rno__row__index |
29 | FROM ( |
30 | SELECT me.id, me.source, me.owner, me.title, me.price, |
760545fa |
31 | owner.name AS owner__name |
41eac664 |
32 | FROM books me |
33 | JOIN owners owner ON owner.id = me.owner |
34 | WHERE ( source = ? ) |
35 | ) me |
36 | ) me |
41eac664 |
37 | WHERE rno__row__index BETWEEN 1 AND 1 |
38 | )', |
39 | [ [ 'source', 'Library' ] ], |
40 | ); |
41 | |
760545fa |
42 | $schema->storage->_sql_maker->quote_char ([qw/ [ ] /]); |
43 | $schema->storage->_sql_maker->name_sep ('.'); |
41eac664 |
44 | |
45 | my $rs_selectas_rel = $schema->resultset ('BooksInLibrary')->search ({}, { |
46 | '+select' => ['owner.name'], |
47 | '+as' => ['owner_name'], |
48 | join => 'owner', |
760545fa |
49 | rows => 1, |
41eac664 |
50 | }); |
51 | |
52 | is_same_sql_bind( |
53 | $rs_selectas_rel->as_query, |
54 | '( |
760545fa |
55 | SELECT [id], [source], [owner], [title], [price], |
56 | [owner_name] |
41eac664 |
57 | FROM ( |
760545fa |
58 | SELECT [id], [source], [owner], [title], [price], |
59 | [owner_name], |
60 | ROW_NUMBER() OVER( ) AS [rno__row__index] |
41eac664 |
61 | FROM ( |
760545fa |
62 | SELECT [me].[id], [me].[source], [me].[owner], [me].[title], [me].[price], |
63 | [owner].[name] AS [owner_name] |
64 | FROM [books] [me] |
65 | JOIN [owners] [owner] ON [owner].[id] = [me].[owner] |
66 | WHERE ( [source] = ? ) |
67 | ) [me] |
68 | ) [me] |
69 | WHERE [rno__row__index] BETWEEN 1 AND 1 |
41eac664 |
70 | )', |
71 | [ [ 'source', 'Library' ] ], |
72 | ); |
a5f843e3 |
73 | |
74 | done_testing; |