Revision history for SQL::Abstract
+ - Fix parsing of ORDER BY foo + ?
- Stop filling in placeholders in `format-sql` since it does not support
passing values for them anyway
- Fix parsing of NOT EXISTS
# this will be included in the $binary_op_re, the distinction is interesting during
# testing as one is tighter than the other, plus mathops have different look
# ahead/behind (e.g. "x"="y" )
-my @math_op_keywords = (qw/ < > != <> = <= >= /);
+my @math_op_keywords = (qw/ - + < > != <> = <= >= /);
my $math_op_re = join ("\n\t|\n", map
{ "(?: (?<= [\\w\\s] | $quote_right ) | \\A )" . quotemeta ($_) . "(?: (?= [\\w\\s] | $quote_left ) | \\z )" }
@math_op_keywords
elsif ($op eq '-MISC' ) {
return join (' ', map $self->_unparse($_, $bindargs, $depth), @{$args});
}
+ elsif ($op =~ qr/^-(ASC|DESC)$/ ) {
+ my $dir = $1;
+ return join (' ', (map $self->_unparse($_, $bindargs, $depth), @{$args}), $dir);
+ }
else {
my ($l, $r) = @{$self->pad_keyword($op, $depth)};
return sprintf "$l%s%s%s$r",
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+use SQL::Abstract::Tree;
+
+my $sqlat = SQL::Abstract::Tree->new({});
+
+is(
+ $sqlat->format('SELECT foo AS bar FROM baz ORDER BY x + ? DESC, baz.g'),
+ 'SELECT foo AS bar FROM baz ORDER BY x + ? DESC, baz.g',
+ 'complex order by correctly reassembled'
+);
+
+done_testing;