From: Matt S Trout Date: Mon, 4 Nov 2013 00:42:59 +0000 (+0000) Subject: use INNER for old mysqls X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9ee59b74604a36e63fed2056db7770342aa0a478;p=dbsrgits%2FData-Query.git use INNER for old mysqls --- diff --git a/lib/Data/Query/Renderer/SQL/MySQL.pm b/lib/Data/Query/Renderer/SQL/MySQL.pm index 25a4929..fe447ed 100644 --- a/lib/Data/Query/Renderer/SQL/MySQL.pm +++ b/lib/Data/Query/Renderer/SQL/MySQL.pm @@ -8,6 +8,17 @@ extends 'Data::Query::Renderer::SQL::Naive'; with 'Data::Query::Renderer::SQL::Slice::LimitXY'; +has needs_inner_join => (is => 'ro', default => sub { 0 }); + +around _format_join_keyword => sub { + my ($orig, $self) = (shift, shift); + my ($dq) = @_; + if ($self->needs_inner_join and $dq->{on} and !$dq->{outer}) { + return $self->_format_keyword('INNER JOIN'); + } + return $self->$orig(@_); +}; + sub _insert_default_values { my ($self) = @_; $self->_format_keyword('VALUES'), qw( ( ) ); diff --git a/lib/Data/Query/Renderer/SQL/Naive.pm b/lib/Data/Query/Renderer/SQL/Naive.pm index df2fe36..dbe4b80 100644 --- a/lib/Data/Query/Renderer/SQL/Naive.pm +++ b/lib/Data/Query/Renderer/SQL/Naive.pm @@ -336,18 +336,9 @@ sub _render_literal { sub _render_join { my ($self, $dq) = @_; my ($left, $right) = @{$dq}{qw(left right)}; - my $join = do { - if ($dq->{outer}) { - $self->_format_keyword(uc($dq->{outer}).' JOIN'); - } elsif ($dq->{on}) { - $self->_format_keyword('JOIN'); - } else { - ',' - } - }; my $rhs = $self->_render($right); [ - $self->_render($left), $join, + $self->_render($left), $self->_format_join_keyword($dq), (is_Join($right) ? ('(', $rhs, ')') : $rhs), ($dq->{on} ? ($self->_format_keyword('ON'), $self->_render($dq->{on})) @@ -355,6 +346,17 @@ sub _render_join { ]; } +sub _format_join_keyword { + my ($self, $dq) = @_; + if ($dq->{outer}) { + $self->_format_keyword(uc($dq->{outer}).' JOIN'); + } elsif ($dq->{on}) { + $self->_format_keyword('JOIN'); + } else { + ',' + } +} + sub _render_where { my ($self, $dq) = @_; my ($from, $where) = @{$dq}{qw(from where)};