From: Matt S Trout Date: Thu, 16 Aug 2012 17:34:23 +0000 (+0100) Subject: minor helper tweaks X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=af2d41558fb8cef5b1d68e51dc0da96d5c35aa73;p=dbsrgits%2FData-Query.git minor helper tweaks --- diff --git a/lib/Data/Query/ExprHelpers.pm b/lib/Data/Query/ExprHelpers.pm index 383b57c..ad1f529 100644 --- a/lib/Data/Query/ExprHelpers.pm +++ b/lib/Data/Query/ExprHelpers.pm @@ -40,14 +40,17 @@ my %map = ( ); sub Literal { + my $subtype = shift; if (ref($_[0])) { return +{ type => DQ_LITERAL, + subtype => $subtype, parts => $_[0], }; } return +{ type => DQ_LITERAL, + subtype => $subtype, literal => $_[0], ($_[1] ? (values => $_[1]) : ()) }; diff --git a/lib/Data/Query/Renderer/SQL/Slice/SubqueryRemap.pm b/lib/Data/Query/Renderer/SQL/Slice/SubqueryRemap.pm index 092d726..261088e 100644 --- a/lib/Data/Query/Renderer/SQL/Slice/SubqueryRemap.pm +++ b/lib/Data/Query/Renderer/SQL/Slice/SubqueryRemap.pm @@ -3,7 +3,7 @@ package Data::Query::Renderer::SQL::Slice::SubqueryRemap; use Data::Query::ExprHelpers; use Moo::Role; -sub _subquery_remap { +sub _subquery_remap_select { my ($self, $orig_select) = @_; my $gensym_count; @@ -24,6 +24,31 @@ sub _subquery_remap { } } @{$orig_select->{select}}; + my @outside_select_list = map { + if (is_Alias) { + Identifier($_->{to}); + } else { + $_; + } + } @inside_select_list; + + return ( + inside_select_list => \@inside_select_list, + outside_select_list => \@outside_select_list, + default_inside_alias => $default_inside_alias, + ); +} + +sub _subquery_remap { + my ($self, $orig_select) = @_; + + my $gensym_count; + my %select_remap = $self->_subquery_remap_select($orig_select); + + my $default_inside_alias = $select_remap{default_inside_alias}; + my @inside_select_list = @{$select_remap{inside_select_list}}; + my @outside_select_list = @{$select_remap{outside_select_list}}; + my %alias_map = map { if (is_Alias and is_Identifier $_->{from}) { +(join('.',@{$_->{from}{elements}}) => Identifier($_->{to})) @@ -34,14 +59,6 @@ sub _subquery_remap { } } @inside_select_list; - my @outside_select_list = map { - if (is_Alias) { - Identifier($_->{to}); - } else { - $_; - } - } @inside_select_list; - my @inside_order; my $inner_body = do { my $order = $orig_select->{from};