From: Matt S Trout Date: Sun, 17 Jul 2011 06:53:00 +0000 (+0000) Subject: metadata for values, order by, values for literals X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f462f860c233998b75949973bf2acb785ef2132;p=dbsrgits%2FData-Query.git metadata for values, order by, values for literals --- diff --git a/lib/Data/Query/Constants.pm b/lib/Data/Query/Constants.pm index 091f587..7512cfd 100644 --- a/lib/Data/Query/Constants.pm +++ b/lib/Data/Query/Constants.pm @@ -12,6 +12,7 @@ use constant +{ DQ_ALIAS => 'Alias', DQ_LITERAL => 'Literal', DQ_JOIN => 'Join', + DQ_ORDER => 'Order', )) }; diff --git a/lib/Data/Query/ExprHelpers.pm b/lib/Data/Query/ExprHelpers.pm index d194313..455461e 100644 --- a/lib/Data/Query/ExprHelpers.pm +++ b/lib/Data/Query/ExprHelpers.pm @@ -11,7 +11,8 @@ sub perl_scalar_value { +{ type => DQ_VALUE, subtype => { Perl => 'Scalar' }, - value => $_[0] + value => $_[0], + $_[1] ? (value_meta => $_[1]) : () } } diff --git a/lib/Data/Query/Renderer/SQL/Naive.pm b/lib/Data/Query/Renderer/SQL/Naive.pm index c35da5c..b2517b0 100644 --- a/lib/Data/Query/Renderer/SQL/Naive.pm +++ b/lib/Data/Query/Renderer/SQL/Naive.pm @@ -3,7 +3,7 @@ package Data::Query::Renderer::SQL::Naive; use strictures 1; use SQL::ReservedWords; use Data::Query::Constants qw( - DQ_IDENTIFIER DQ_OPERATOR DQ_VALUE DQ_JOIN DQ_ALIAS + DQ_IDENTIFIER DQ_OPERATOR DQ_VALUE DQ_JOIN DQ_ALIAS DQ_ORDER ); sub new { @@ -186,7 +186,7 @@ sub _render_select { my @select = map [ ($_->{type} eq DQ_ALIAS - ? $self->_render_alias($_, 'AS') + ? $self->_render_alias($_, $self->_format_keyword('AS')) : $self->_render($_) ), ',' @@ -232,7 +232,7 @@ sub _render_literal { die "Can't render non-SQL literal"; } return [ - $dq->{literal}, + $dq->{literal}, @{$dq->{values}||[]} ]; } @@ -244,4 +244,35 @@ sub _render_join { [ $self->_render($left), ',', $self->_render($right) ]; } +sub _render_where { + my ($self, $dq) = @_; + my ($from, $where) = @{$dq}{qw(from where)}; + [ + ($from ? $self->_render($from) : ()), + $self->_format_keyword('WHERE'), + $self->_render($where) + ] +} + +sub _render_order { + my ($self, $dq) = @_; + my @ret = ( + $self->_format_keyword('ORDER BY'), + $self->_render($dq->{by}), + ($dq->{direction} ? $self->_format_keyword($dq->{direction}) : ()) + ); + my $from; + while ($from = $dq->{from}) { + last unless $from->{type} eq DQ_ORDER; + $dq = $from; + push @ret, ( + ',', + $self->_render($dq->{by}), + ($dq->{direction} ? $self->_format_keyword($dq->{direction}) : ()) + ); + } + unshift @ret, $self->_render($from) if $from; + \@ret; +} + 1;