From: Matt S Trout Date: Mon, 16 Apr 2012 12:34:10 +0000 (+0000) Subject: rename alias node content X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=07b0f7e08e4306ff180223809842668e4837865b;p=dbsrgits%2FData-Query.git rename alias node content --- diff --git a/lib/Data/Query/Renderer/SQL/Naive.pm b/lib/Data/Query/Renderer/SQL/Naive.pm index 5f31efe..56cdb3b 100644 --- a/lib/Data/Query/Renderer/SQL/Naive.pm +++ b/lib/Data/Query/Renderer/SQL/Naive.pm @@ -28,6 +28,8 @@ has lc_keywords => (is => 'ro', default => sub { 0 }); has always_quote => (is => 'ro', default => sub { 0 }); +has collapse_aliases => (is => 'ro', default => sub { 1 }); + sub _default_simple_ops { +{ (map +($_ => 'binop'), qw(= > < >= <= != LIKE), 'NOT LIKE' ), @@ -293,15 +295,17 @@ sub _render_alias { my ($self, $dq, $as) = @_; # FROM foo foo -> FROM foo # FROM foo.bar bar -> FROM foo.bar - if ($dq->{alias}{type} eq DQ_IDENTIFIER) { - if ($dq->{alias}{elements}[-1] eq $dq->{as}) { - return $self->_render($dq->{alias}); + if ($self->collapse_aliases) { + if ($dq->{from}{type} eq DQ_IDENTIFIER) { + if ($dq->{from}{elements}[-1] eq $dq->{to}) { + return $self->_render($dq->{from}); + } } } return [ - $self->_render($dq->{alias}), + $self->_render($dq->{from}), $as || ' ', - $self->_render_identifier({ elements => [ $dq->{as} ] }) + $self->_render_identifier({ elements => [ $dq->{to} ] }) ]; } @@ -323,7 +327,7 @@ sub _render_literal { sub _render_join { my ($self, $dq) = @_; - my ($left, $right) = @{$dq->{join}}; + my ($left, $right) = @{$dq}{qw(left right)}; my $join = do { if ($dq->{outer}) { $self->_format_keyword(uc($dq->{outer}).' JOIN');