From: Matt S Trout Date: Sat, 14 Apr 2012 15:41:21 +0000 (+0000) Subject: order inside select node X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=10d55ab8e6e3e635870f6face172d33f14b7bfb4;p=dbsrgits%2FSQL-Abstract.git order inside select node --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index e45071b..41c1786 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -340,29 +340,31 @@ sub select { shift->_render_sqla(select => @_) } sub _select_to_dq { my ($self, $table, $fields, $where, $order) = @_; - my $final_dq = $self->_select_body_to_dq($table, $fields, $where); + my $source_dq = $self->_source_to_dq($table, $where); - if ($order) { - $final_dq = $self->_order_by_to_dq($order, undef, $final_dq); - } + my $ordered_dq = do { + if ($order) { + $self->_order_by_to_dq($order, undef, $source_dq); + } else { + $source_dq + } + }; - return $final_dq; + return $self->_select_list_to_dq($fields, $ordered_dq); } -sub _select_body_to_dq { - my ($self, $table, $fields, $where) = @_; +sub _select_list_to_dq { + my ($self, $fields, $from_dq) = @_; $fields ||= '*'; - my $source_dq = $self->_source_to_dq($table, $where); - return +{ type => DQ_SELECT, select => [ map $self->_select_field_to_dq($_), ref($fields) eq 'ARRAY' ? @$fields : $fields ], - from => $source_dq, + from => $from_dq, }; }