next if $in_sel_index->{$chunk};
$extra_order_sel->{$chunk} ||= $self->_quote (
- 'ORDER__BY__' . scalar keys %{$extra_order_sel||{}}
+ 'ORDER__BY__' . sprintf '%03d', scalar keys %{$extra_order_sel||{}}
);
}
{
order_by => \'title DESC',
order_inner => 'title DESC',
- order_outer => 'ORDER__BY__1 ASC',
- order_req => 'ORDER__BY__1 DESC',
- exselect_outer => 'ORDER__BY__1',
- exselect_inner => 'title AS ORDER__BY__1',
+ order_outer => 'ORDER__BY__001 ASC',
+ order_req => 'ORDER__BY__001 DESC',
+ exselect_outer => 'ORDER__BY__001',
+ exselect_inner => 'title AS ORDER__BY__001',
},
{
order_by => { -asc => 'title' },
order_inner => 'title ASC',
- order_outer => 'ORDER__BY__1 DESC',
- order_req => 'ORDER__BY__1 ASC',
- exselect_outer => 'ORDER__BY__1',
- exselect_inner => 'title AS ORDER__BY__1',
+ order_outer => 'ORDER__BY__001 DESC',
+ order_req => 'ORDER__BY__001 ASC',
+ exselect_outer => 'ORDER__BY__001',
+ exselect_inner => 'title AS ORDER__BY__001',
},
{
order_by => { -desc => 'title' },
order_inner => 'title DESC',
- order_outer => 'ORDER__BY__1 ASC',
- order_req => 'ORDER__BY__1 DESC',
- exselect_outer => 'ORDER__BY__1',
- exselect_inner => 'title AS ORDER__BY__1',
+ order_outer => 'ORDER__BY__001 ASC',
+ order_req => 'ORDER__BY__001 DESC',
+ exselect_outer => 'ORDER__BY__001',
+ exselect_inner => 'title AS ORDER__BY__001',
},
{
order_by => 'title',
order_inner => 'title',
- order_outer => 'ORDER__BY__1 DESC',
- order_req => 'ORDER__BY__1',
- exselect_outer => 'ORDER__BY__1',
- exselect_inner => 'title AS ORDER__BY__1',
+ order_outer => 'ORDER__BY__001 DESC',
+ order_req => 'ORDER__BY__001',
+ exselect_outer => 'ORDER__BY__001',
+ exselect_inner => 'title AS ORDER__BY__001',
},
{
order_by => [ qw{ title me.owner} ],
order_inner => 'title, me.owner',
- order_outer => 'ORDER__BY__1 DESC, me.owner DESC',
- order_req => 'ORDER__BY__1, me.owner',
- exselect_outer => 'ORDER__BY__1',
- exselect_inner => 'title AS ORDER__BY__1',
+ order_outer => 'ORDER__BY__001 DESC, me.owner DESC',
+ order_req => 'ORDER__BY__001, me.owner',
+ exselect_outer => 'ORDER__BY__001',
+ exselect_inner => 'title AS ORDER__BY__001',
},
{
order_by => ['title', { -desc => 'bar' } ],
order_inner => 'title, bar DESC',
- order_outer => 'ORDER__BY__1 DESC, ORDER__BY__2 ASC',
- order_req => 'ORDER__BY__1, ORDER__BY__2 DESC',
- exselect_outer => 'ORDER__BY__1, ORDER__BY__2',
- exselect_inner => 'title AS ORDER__BY__1, bar AS ORDER__BY__2',
+ order_outer => 'ORDER__BY__001 DESC, ORDER__BY__002 ASC',
+ order_req => 'ORDER__BY__001, ORDER__BY__002 DESC',
+ exselect_outer => 'ORDER__BY__001, ORDER__BY__002',
+ exselect_inner => 'title AS ORDER__BY__001, bar AS ORDER__BY__002',
},
{
order_by => { -asc => [qw{ title bar }] },
order_inner => 'title ASC, bar ASC',
- order_outer => 'ORDER__BY__1 DESC, ORDER__BY__2 DESC',
- order_req => 'ORDER__BY__1 ASC, ORDER__BY__2 ASC',
- exselect_outer => 'ORDER__BY__1, ORDER__BY__2',
- exselect_inner => 'title AS ORDER__BY__1, bar AS ORDER__BY__2',
+ order_outer => 'ORDER__BY__001 DESC, ORDER__BY__002 DESC',
+ order_req => 'ORDER__BY__001 ASC, ORDER__BY__002 ASC',
+ exselect_outer => 'ORDER__BY__001, ORDER__BY__002',
+ exselect_inner => 'title AS ORDER__BY__001, bar AS ORDER__BY__002',
},
{
order_by => [
{ -asc => [qw{me.owner sensors}]},
],
order_inner => 'title, bar DESC, me.owner ASC, sensors ASC',
- order_outer => 'ORDER__BY__1 DESC, ORDER__BY__2 ASC, me.owner DESC, ORDER__BY__3 DESC',
- order_req => 'ORDER__BY__1, ORDER__BY__2 DESC, me.owner ASC, ORDER__BY__3 ASC',
- exselect_outer => 'ORDER__BY__1, ORDER__BY__2, ORDER__BY__3',
- exselect_inner => 'title AS ORDER__BY__1, bar AS ORDER__BY__2, sensors AS ORDER__BY__3',
+ order_outer => 'ORDER__BY__001 DESC, ORDER__BY__002 ASC, me.owner DESC, ORDER__BY__003 DESC',
+ order_req => 'ORDER__BY__001, ORDER__BY__002 DESC, me.owner ASC, ORDER__BY__003 ASC',
+ exselect_outer => 'ORDER__BY__001, ORDER__BY__002, ORDER__BY__003',
+ exselect_inner => 'title AS ORDER__BY__001, bar AS ORDER__BY__002, sensors AS ORDER__BY__003',
},
) {
my $o_sel = $ord_set->{exselect_outer}
$books_45_and_owners->search ({}, { group_by => 'title', order_by => 'title' })->as_query,
'(SELECT me.id, me.source, me.owner, me.price, owner.id, owner.name
FROM (
- SELECT me.id, me.source, me.owner, me.price, ORDER__BY__1 AS title
+ SELECT me.id, me.source, me.owner, me.price, ORDER__BY__001 AS title
FROM (
- SELECT me.id, me.source, me.owner, me.price, ORDER__BY__1
+ SELECT me.id, me.source, me.owner, me.price, ORDER__BY__001
FROM (
- SELECT me.id, me.source, me.owner, me.price, title AS ORDER__BY__1
+ SELECT me.id, me.source, me.owner, me.price, title AS ORDER__BY__001
FROM books me
JOIN owners owner ON owner.id = me.owner
WHERE ( source = ? )
ORDER BY title
FETCH FIRST 5 ROWS ONLY
) me
- ORDER BY ORDER__BY__1 DESC
+ ORDER BY ORDER__BY__001 DESC
FETCH FIRST 2 ROWS ONLY
) me
- ORDER BY ORDER__BY__1
+ ORDER BY ORDER__BY__001
) me
JOIN owners owner ON owner.id = me.owner
WHERE ( source = ? )
order_by => 'me.id',
});
-# SELECT [owner_name], [owner_books] FROM (
-# SELECT [owner_name], [owner_books], [ORDER__BY__1], ROW_NUMBER() OVER( ORDER BY [ORDER__BY__1] ) AS [rno__row__index] FROM (
-# SELECT [owner].[name] AS [owner_name], (SELECT COUNT( * ) FROM [owners] [owner] WHERE ( ( [count].[id] = [owner].[id] AND [count].[name] = ? ) )) AS [owner_books], [me].[id] AS [ORDER__BY__1] FROM [books] [me] JOIN [owners] [owner] ON [owner].[id] = [me].[owner] WHERE ( [source] = ? )
-# ) [me]
-# ) [me] WHERE [rno__row__index] >= ? AND [rno__row__index] <= ?
-
is_same_sql_bind(
$rs_selectas_rel->as_query,
'(
SELECT [owner_name], [owner_books]
FROM (
- SELECT [owner_name], [owner_books], ROW_NUMBER() OVER( ORDER BY [ORDER__BY__1] ) AS [rno__row__index]
+ SELECT [owner_name], [owner_books], ROW_NUMBER() OVER( ORDER BY [ORDER__BY__001] ) AS [rno__row__index]
FROM (
SELECT [owner].[name] AS [owner_name],
( SELECT COUNT( * ) FROM [owners] [owner]
WHERE [count].[id] = [owner].[id] and [count].[name] = ? ) AS [owner_books],
- [me].[id] AS [ORDER__BY__1]
+ [me].[id] AS [ORDER__BY__001]
FROM [books] [me]
JOIN [owners] [owner] ON [owner].[id] = [me].[owner]
WHERE ( [source] = ? )
{
order_by => \'title DESC',
order_inner => 'title DESC',
- order_outer => 'ORDER__BY__1 ASC',
- order_req => 'ORDER__BY__1 DESC',
- exselect_outer => 'ORDER__BY__1',
- exselect_inner => 'title AS ORDER__BY__1',
+ order_outer => 'ORDER__BY__001 ASC',
+ order_req => 'ORDER__BY__001 DESC',
+ exselect_outer => 'ORDER__BY__001',
+ exselect_inner => 'title AS ORDER__BY__001',
},
{
order_by => { -asc => 'title' },
order_inner => 'title ASC',
- order_outer => 'ORDER__BY__1 DESC',
- order_req => 'ORDER__BY__1 ASC',
- exselect_outer => 'ORDER__BY__1',
- exselect_inner => 'title AS ORDER__BY__1',
+ order_outer => 'ORDER__BY__001 DESC',
+ order_req => 'ORDER__BY__001 ASC',
+ exselect_outer => 'ORDER__BY__001',
+ exselect_inner => 'title AS ORDER__BY__001',
},
{
order_by => { -desc => 'title' },
order_inner => 'title DESC',
- order_outer => 'ORDER__BY__1 ASC',
- order_req => 'ORDER__BY__1 DESC',
- exselect_outer => 'ORDER__BY__1',
- exselect_inner => 'title AS ORDER__BY__1',
+ order_outer => 'ORDER__BY__001 ASC',
+ order_req => 'ORDER__BY__001 DESC',
+ exselect_outer => 'ORDER__BY__001',
+ exselect_inner => 'title AS ORDER__BY__001',
},
{
order_by => 'title',
order_inner => 'title',
- order_outer => 'ORDER__BY__1 DESC',
- order_req => 'ORDER__BY__1',
- exselect_outer => 'ORDER__BY__1',
- exselect_inner => 'title AS ORDER__BY__1',
+ order_outer => 'ORDER__BY__001 DESC',
+ order_req => 'ORDER__BY__001',
+ exselect_outer => 'ORDER__BY__001',
+ exselect_inner => 'title AS ORDER__BY__001',
},
{
order_by => [ qw{ title me.owner} ],
order_inner => 'title, me.owner',
- order_outer => 'ORDER__BY__1 DESC, me.owner DESC',
- order_req => 'ORDER__BY__1, me.owner',
- exselect_outer => 'ORDER__BY__1',
- exselect_inner => 'title AS ORDER__BY__1',
+ order_outer => 'ORDER__BY__001 DESC, me.owner DESC',
+ order_req => 'ORDER__BY__001, me.owner',
+ exselect_outer => 'ORDER__BY__001',
+ exselect_inner => 'title AS ORDER__BY__001',
},
{
order_by => ['title', { -desc => 'bar' } ],
order_inner => 'title, bar DESC',
- order_outer => 'ORDER__BY__1 DESC, ORDER__BY__2 ASC',
- order_req => 'ORDER__BY__1, ORDER__BY__2 DESC',
- exselect_outer => 'ORDER__BY__1, ORDER__BY__2',
- exselect_inner => 'title AS ORDER__BY__1, bar AS ORDER__BY__2',
+ order_outer => 'ORDER__BY__001 DESC, ORDER__BY__002 ASC',
+ order_req => 'ORDER__BY__001, ORDER__BY__002 DESC',
+ exselect_outer => 'ORDER__BY__001, ORDER__BY__002',
+ exselect_inner => 'title AS ORDER__BY__001, bar AS ORDER__BY__002',
},
{
order_by => { -asc => [qw{ title bar }] },
order_inner => 'title ASC, bar ASC',
- order_outer => 'ORDER__BY__1 DESC, ORDER__BY__2 DESC',
- order_req => 'ORDER__BY__1 ASC, ORDER__BY__2 ASC',
- exselect_outer => 'ORDER__BY__1, ORDER__BY__2',
- exselect_inner => 'title AS ORDER__BY__1, bar AS ORDER__BY__2',
+ order_outer => 'ORDER__BY__001 DESC, ORDER__BY__002 DESC',
+ order_req => 'ORDER__BY__001 ASC, ORDER__BY__002 ASC',
+ exselect_outer => 'ORDER__BY__001, ORDER__BY__002',
+ exselect_inner => 'title AS ORDER__BY__001, bar AS ORDER__BY__002',
},
{
order_by => [
{ -asc => [qw{me.owner sensors}]},
],
order_inner => 'title, bar DESC, me.owner ASC, sensors ASC',
- order_outer => 'ORDER__BY__1 DESC, ORDER__BY__2 ASC, me.owner DESC, ORDER__BY__3 DESC',
- order_req => 'ORDER__BY__1, ORDER__BY__2 DESC, me.owner ASC, ORDER__BY__3 ASC',
- exselect_outer => 'ORDER__BY__1, ORDER__BY__2, ORDER__BY__3',
- exselect_inner => 'title AS ORDER__BY__1, bar AS ORDER__BY__2, sensors AS ORDER__BY__3',
+ order_outer => 'ORDER__BY__001 DESC, ORDER__BY__002 ASC, me.owner DESC, ORDER__BY__003 DESC',
+ order_req => 'ORDER__BY__001, ORDER__BY__002 DESC, me.owner ASC, ORDER__BY__003 ASC',
+ exselect_outer => 'ORDER__BY__001, ORDER__BY__002, ORDER__BY__003',
+ exselect_inner => 'title AS ORDER__BY__001, bar AS ORDER__BY__002, sensors AS ORDER__BY__003',
},
) {
my $o_sel = $ord_set->{exselect_outer}
$books_45_and_owners->search ({}, { group_by => 'title', order_by => 'title' })->as_query,
'(SELECT me.id, me.source, me.owner, me.price, owner.id, owner.name
FROM (
- SELECT me.id, me.source, me.owner, me.price, ORDER__BY__1 AS title
+ SELECT me.id, me.source, me.owner, me.price, ORDER__BY__001 AS title
FROM (
SELECT TOP 2
- me.id, me.source, me.owner, me.price, ORDER__BY__1
+ me.id, me.source, me.owner, me.price, ORDER__BY__001
FROM (
SELECT TOP 5
- me.id, me.source, me.owner, me.price, title AS ORDER__BY__1
+ me.id, me.source, me.owner, me.price, title AS ORDER__BY__001
FROM books me
JOIN owners owner ON owner.id = me.owner
WHERE ( source = ? )
GROUP BY title
ORDER BY title
) me
- ORDER BY ORDER__BY__1 DESC
+ ORDER BY ORDER__BY__001 DESC
) me
- ORDER BY ORDER__BY__1
+ ORDER BY ORDER__BY__001
) me
JOIN owners owner ON owner.id = me.owner
WHERE ( source = ? )
my $ordered_sql = '(
SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, owner__id, owner__name, bar, baz, ROW_NUMBER() OVER( ORDER BY ORDER__BY__1, ORDER__BY__2 ) AS rno__row__index
+ SELECT me.id, owner__id, owner__name, bar, baz, ROW_NUMBER() OVER( ORDER BY ORDER__BY__001, ORDER__BY__002 ) AS rno__row__index
FROM (
SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz,
- ? / ? AS ORDER__BY__1, ? AS ORDER__BY__2
+ ? / ? AS ORDER__BY__001, ? AS ORDER__BY__002
FROM books me
JOIN owners owner
ON owner.id = me.owner
'(
SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT me.id, owner__id, owner__name, bar, baz, ORDER__BY__1, ORDER__BY__2
+ SELECT me.id, owner__id, owner__name, bar, baz, ORDER__BY__001, ORDER__BY__002
FROM (
- SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz, ? / ? AS ORDER__BY__1, ? AS ORDER__BY__2
+ SELECT me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz, ? / ? AS ORDER__BY__001, ? AS ORDER__BY__002
FROM books me
JOIN owners owner
ON owner.id = me.owner
ORDER BY ? / ?, ?
FETCH FIRST 7 ROWS ONLY
) me
- ORDER BY ORDER__BY__1 DESC, ORDER__BY__2 DESC
+ ORDER BY ORDER__BY__001 DESC, ORDER__BY__002 DESC
FETCH FIRST 4 ROWS ONLY
) me
- ORDER BY ORDER__BY__1, ORDER__BY__2
+ ORDER BY ORDER__BY__001, ORDER__BY__002
)',
[
@select_bind,
'(
SELECT me.id, owner__id, owner__name, bar, baz
FROM (
- SELECT TOP 4 me.id, owner__id, owner__name, bar, baz, ORDER__BY__1, ORDER__BY__2
+ SELECT TOP 4 me.id, owner__id, owner__name, bar, baz, ORDER__BY__001, ORDER__BY__002
FROM (
- SELECT TOP 7 me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz, ? / ? AS ORDER__BY__1, ? AS ORDER__BY__2
+ SELECT TOP 7 me.id, owner.id AS owner__id, owner.name AS owner__name, ? * ? AS bar, ? AS baz, ? / ? AS ORDER__BY__001, ? AS ORDER__BY__002
FROM books me
JOIN owners owner
ON owner.id = me.owner
HAVING ?
ORDER BY ? / ?, ?
) me
- ORDER BY ORDER__BY__1 DESC, ORDER__BY__2 DESC
+ ORDER BY ORDER__BY__001 DESC, ORDER__BY__002 DESC
) me
- ORDER BY ORDER__BY__1, ORDER__BY__2
+ ORDER BY ORDER__BY__001, ORDER__BY__002
)',
[
@select_bind,