}
}
+sub _split_order_chunk {
+ my ($self, $chunk) = @_;
+
+ # strip off sort modifiers, but always succeed, so $1 gets reset
+ $chunk =~ s/ (?: \s+ (ASC|DESC) )? \s* $//ix;
+
+ return (
+ $chunk,
+ ( $1 and uc($1) eq 'DESC' ) ? 1 : 0,
+ );
+}
+
sub _table {
# optimized due to hotttnesss
# my ($self, $from) = @_;
for my $ch ($self->_order_by_chunks ($inner_order)) {
$ch = $ch->[0] if ref $ch eq 'ARRAY';
- my $is_desc = (
- $ch =~ s/\s+ ( ASC|DESC ) \s* $//ix
- and
- uc($1) eq 'DESC'
- ) ? 1 : 0;
- push @out_chunks, \join (' ', $ch, $is_desc ? 'ASC' : 'DESC' );
+ ($ch, my $is_desc) = $self->_split_order_chunk($ch);
+
+ # !NOTE! outside chunks come in reverse order ( !$is_desc )
+ push @out_chunks, { ($is_desc ? '-asc' : '-desc') => \$ch };
}
$sq_attrs->{order_by_middle} = $self->_order_by (\@out_chunks);
for my $bit (@order_bits) {
- my $is_desc = (
- $bit =~ s/\s+ ( ASC|DESC ) \s* $//ix
- and
- uc($1) eq 'DESC'
- ) ? 1 : 0;
+ ($bit, my $is_desc) = $self->_split_order_chunk($bit);
push @is_desc, $is_desc;
push @unqualified_names, $usable_order_ci->{$bit}{-colname};
for my $chunk ($self->_order_by_chunks ($rs_attrs->{order_by})) {
# order with bind
$chunk = $chunk->[0] if (ref $chunk) eq 'ARRAY';
- $chunk =~ s/\s+ (?: ASC|DESC ) \s* $//ix;
+ ($chunk) = $self->_split_order_chunk($chunk);
next if $in_sel_index->{$chunk};
# skip ourselves
next if $chunk =~ $own_re;
- my $is_desc = $chunk =~ s/\sDESC$//i;
- $chunk =~ s/\sASC$//i;
+ ($chunk, my $is_desc) = $sql_maker->_split_order_chunk($chunk);
# maybe our own unqualified column
my $ord_bit = (
my @chunks;
for ($sql_maker->_order_by_chunks ($order_by) ) {
my $chunk = ref $_ ? [ @$_ ] : [ $_ ];
- $chunk->[0] =~ s/\s+ (?: ASC|DESC ) \s* $//ix;
+ ($chunk->[0]) = $sql_maker->_split_order_chunk($chunk->[0]);
# order criteria may have come back pre-quoted (literals and whatnot)
# this is fragile, but the best we can currently do