X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FData%2FQuery%2FRenderer%2FSQL%2FSlice%2FGenericSubquery.pm;fp=lib%2FData%2FQuery%2FRenderer%2FSQL%2FSlice%2FGenericSubquery.pm;h=41d1f3755c12a3178852a828f2dbb5374869a2f9;hb=1cc80bbd262e8d8fcbf9a354d6d860cbc51645b2;hp=5320cbbf6e756ef678b8f13a0f222b6af86e099e;hpb=db628d9ab39bf80f88432a1c2cc749152e5ff13d;p=dbsrgits%2FData-Query.git 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('*') ]) ],