From: Matt S Trout Date: Mon, 4 Nov 2013 03:04:55 +0000 (+0000) Subject: add support for nulls => "none" in order nodes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1cc80bbd262e8d8fcbf9a354d6d860cbc51645b2;p=dbsrgits%2FData-Query.git add support for nulls => "none" in order nodes --- diff --git a/lib/Data/Query/Renderer/SQL/Slice/GenericSubquery.pm b/lib/Data/Query/Renderer/SQL/Slice/GenericSubquery.pm index 5320cbb..41d1f37 100644 --- a/lib/Data/Query/Renderer/SQL/Slice/GenericSubquery.pm +++ b/lib/Data/Query/Renderer/SQL/Slice/GenericSubquery.pm @@ -46,7 +46,8 @@ sub _render_slice { or (@{$order->{by}{elements}} == 1)) ) { push @main_order, [ - $outside->{by}, $order->{by}{elements}[-1], $order->{reverse} + $outside->{by}, $order->{by}{elements}[-1], $order->{reverse}, + $order->{nulls} ]; } else { last; @@ -59,27 +60,40 @@ sub _render_slice { my $lhs = $b->[0]; my $rhs = Identifier($count_alias, $b->[1]); ($lhs, $rhs) = ($rhs, $lhs) if $b->[2]; - my $this = Operator($op_or, [ - Operator($op_and, [ - Operator({ 'SQL.Naive' => 'IS NOT NULL' }, [ $lhs ]), - Operator({ 'SQL.Naive' => 'IS NULL' }, [ $rhs ]), - ]), - Operator({ 'SQL.Naive' => '>' }, [ $lhs, $rhs ]), - ]); - ($a - ? Operator($op_or, [ - $this, - Operator($op_and, [ - Operator($op_or, [ - Operator($op_and, [ - map Operator({ 'SQL.Naive' => 'IS NULL' }, [ $_ ]), $lhs, $rhs - ]), - Operator({ 'SQL.Naive' => '=' }, [ $lhs, $rhs ]) + my $no_nulls = ($b->[3]||'') eq 'none'; + my ($this) = map { + $no_nulls + ? $_ + : Operator($op_or, [ + Operator($op_and, [ + Operator({ 'SQL.Naive' => 'IS NOT NULL' }, [ $lhs ]), + Operator({ 'SQL.Naive' => 'IS NULL' }, [ $rhs ]), ]), - $a + $_ ]) - ]) - : $this) + } Operator({ 'SQL.Naive' => '>' }, [ $lhs, $rhs ]); + my $final = ( + $a + ? Operator($op_or, [ + $this, + Operator($op_and, [ + (map { + $no_nulls + ? $_ + : Operator($op_or, [ + Operator($op_and, [ + map Operator({ 'SQL.Naive' => 'IS NULL' }, [ $_ ]), + $lhs, $rhs + ]), + $_, + ]) + } Operator({ 'SQL.Naive' => '=' }, [ $lhs, $rhs ])), + $a + ]) + ]) + : $this + ); + $final; } @main_order, undef; my $count_sel = Select( [ Operator({ 'SQL.Naive' => 'apply' }, [ Identifier('COUNT'), Identifier('*') ]) ],