X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract%2FExtraClauses.pm;h=9af44a585b1f640cd9ca7a52d8f34ef24dcbf73e;hb=38e67490d05429a527277addc383daac165e4db7;hp=9eb04a8e3f9ce93f0a246a9c7022ab72222e2454;hpb=7b811acd927a74444d495bbf8508e57c3144faa3;p=scpubgit%2FQ-Branch.git diff --git a/lib/SQL/Abstract/ExtraClauses.pm b/lib/SQL/Abstract/ExtraClauses.pm index 9eb04a8..9af44a5 100644 --- a/lib/SQL/Abstract/ExtraClauses.pm +++ b/lib/SQL/Abstract/ExtraClauses.pm @@ -87,7 +87,7 @@ sub register_defaults { $self->clause_renderer('select.setop' => sub { my ($self, undef, $setop) = @_; - @{ $self->render_aqt($setop) }; + $self->render_aqt($setop); }); $self->renderer($_ => sub { @@ -116,22 +116,33 @@ sub register_defaults { qw(union intersect except) ); + my $expand_alias = sub { + my ($self, $to_expand) = @_; + [ map $self->expand_expr($_, -ident), + ref($to_expand) eq 'ARRAY' + ? @$to_expand + : $to_expand + ] + }; $self->clause_expander('select.with' => my $with_expander = sub { my ($self, $name, $with) = @_; my (undef, $type) = split '_', $name; if (ref($with) eq 'HASH') { return +{ %$with, - queries => [ map $self->expand_expr($_), @{$with->{queries}} ] + queries => [ + map +[ + $self->$expand_alias($_->[0]), + $self->expand_expr($_->[1]), + ], @{$with->{queries}} + ] } } my @with = @$with; my @exp; - while (my ($name, $query) = splice @with, 0, 2) { - my @n = map $self->expand_expr($_, -ident), - ref($name) eq 'ARRAY' ? @$name : $name; + while (my ($alias, $query) = splice @with, 0, 2) { push @exp, [ - \@n, + $self->$expand_alias($alias), $self->expand_expr($query) ]; } @@ -140,16 +151,16 @@ sub register_defaults { $self->clause_expander('select.with_recursive', $with_expander); $self->clause_renderer('select.with' => sub { my ($self, undef, $with) = @_; - my $q_part = [ $self->join_query_parts(', ', + my $q_part = $self->join_query_parts(', ', map { my ($alias, $query) = @$_; - [ $self->join_query_parts(' ', + $self->join_query_parts(' ', $self->_render_alias($alias), $self->format_keyword('as'), $query, - ) ] + ) } @{$with->{queries}} - ) ]; + ); return $self->join_query_parts(' ', $self->format_keyword(join '_', 'with', ($with->{type}||'')), $q_part, @@ -167,6 +178,7 @@ sub _expand_select_clause_from { sub _expand_from_list { my ($self, undef, $args) = @_; if (ref($args) eq 'HASH') { + return $args if $args->{-from_list}; return { -from_list => [ $self->expand_expr($args) ] }; } my @list; @@ -259,12 +271,12 @@ sub _render_alias { return (@cols ? $self->join_query_parts('', $as, - [ '(' ], - [ $self->join_query_parts( - ', ', - @cols - ) ], - [ ')' ], + '(', + $self->join_query_parts( + ', ', + @cols + ), + ')', ) : $self->render_aqt($as) );