From: Matt S Trout Date: Mon, 17 Sep 2018 02:49:06 +0000 (+0000) Subject: order_by done sanely; cut 1 X-Git-Tag: v2.000000~3^2~456 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b28a4ceff3b1d666df7b23ca7ecaf57e281f8db2;p=dbsrgits%2FSQL-Abstract.git order_by done sanely; cut 1 --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index ef21f21..5389c92 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -1059,13 +1059,14 @@ sub _open_outer_paren { sub _order_by { my ($self, $arg) = @_; - my (@sql, @bind); - for my $c ($self->_order_by_chunks($arg) ) { - $self->_SWITCH_refkind($c, { - SCALAR => sub { push @sql, $c }, - ARRAYREF => sub { push @sql, shift @$c; push @bind, @$c }, - }); - } + my @chunks = $self->_order_by_chunks($arg); + + my @sql; + my @bind = map { + my ($s, @b) = $self->_render_expr($_); + push @sql, $s; + @b; + } @chunks; my $sql = @sql ? sprintf('%s %s', @@ -1090,14 +1091,14 @@ sub _order_by_chunks { ARRAYREFREF => sub { my ($s, @b) = @$$arg; $self->_assert_bindval_matches_bindtype(@b); - [ $s, @b ]; + +{ -literal => [ $s, @b ] }; }, - SCALAR => sub {$self->_quote($arg)}, + SCALAR => sub { +{ -ident => $arg } }, UNDEF => sub {return () }, - SCALARREF => sub {$$arg}, # literal SQL, no quoting + SCALARREF => sub { +{ -literal => [ $$arg ] } }, HASHREF => sub { # get first pair in hash @@ -1113,20 +1114,11 @@ sub _order_by_chunks { my @ret; for my $c ($self->_order_by_chunks($val)) { - my ($sql, @bind); - - $self->_SWITCH_refkind($c, { - SCALAR => sub { - $sql = $c; - }, - ARRAYREF => sub { - ($sql, @bind) = @$c; - }, - }); + my ($sql, @bind) = $self->_render_expr($c); $sql = $sql . ' ' . $self->_sqlcase($direction); - push @ret, [ $sql, @bind]; + push @ret, { -literal => [ $sql, @bind ] }; } return @ret;