}
else {
my ($l, $r) = @{$self->pad_keyword($op, $depth)};
- return sprintf "$l%s%s%s$r",
- $self->format_keyword($op),
+
+ my $rhs = $self->_unparse($args, $bindargs, $depth);
+
+ return sprintf "$l%s$r", join(
( ref $args eq 'ARRAY' and @{$args} == 1 and $args->[0][0] eq '-PAREN' )
? '' # mysql--
: ' '
,
- $self->_unparse($args, $bindargs, $depth),
- ;
+ $self->format_keyword($op),
+ (length $rhs ? $rhs : () ),
+ );
}
}
} while ($changes);
}
+sub _strip_asc_from_order_by {
+ my ($self, $ast) = @_;
+
+ return $ast if (
+ ref $ast ne 'ARRAY'
+ or
+ $ast->[0] ne 'ORDER BY'
+ );
+
+
+ my $to_replace;
+
+ if (@{$ast->[1]} == 1 and $ast->[1][0][0] eq '-ASC') {
+ $to_replace = [ $ast->[1][0] ];
+ }
+ elsif (@{$ast->[1]} == 1 and $ast->[1][0][0] eq '-LIST') {
+ $to_replace = [ grep { $_->[0] eq '-ASC' } @{$ast->[1][0][1]} ];
+ }
+
+ @$_ = @{$_->[1][0]} for @$to_replace;
+
+ $ast;
+}
+
sub format { my $self = shift; $self->unparse($self->parse($_[0]), $_[1]) }
1;