From: Arthur Axel 'fREW' Schmidt Date: Fri, 20 Apr 2012 18:46:28 +0000 (-0500) Subject: fix regression introduced in 6f2a5b6 X-Git-Tag: v1.73_01~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=73835ff0;p=dbsrgits%2FSQL-Abstract.git fix regression introduced in 6f2a5b6 --- diff --git a/Changes b/Changes index f42564f..0d05149 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ 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 diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 7ee5c44..dedd8f3 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -99,7 +99,7 @@ $expr_start_re = qr/ $op_look_behind (?i: $expr_start_re ) $op_look_ahead /x; # 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 @@ -590,6 +590,10 @@ sub _unparse { 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", diff --git a/t/23reassembly-bugs.t b/t/23reassembly-bugs.t new file mode 100644 index 0000000..0954dd4 --- /dev/null +++ b/t/23reassembly-bugs.t @@ -0,0 +1,15 @@ +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;