fix and regression test for RT #62642
[dbsrgits/DBIx-Class.git] / t / sqlmaker / limit_dialects / rno.t
CommitLineData
a5f843e3 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7use DBIC::SqlMakerTest;
8
9my $schema = DBICTest->init_schema;
10
a5f843e3 11$schema->storage->_sql_maker->limit_dialect ('RowNumberOver');
12
41eac664 13my $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 20is_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
45my $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
52is_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
74done_testing;