From: Matt S Trout Date: Thu, 19 Sep 2019 19:16:44 +0000 (+0000) Subject: fix deep empty expr to render nothing X-Git-Tag: v2.000000~3^2~139 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3df759f83ad806f9142b94fc56ed895233bb25f5;p=dbsrgits%2FSQL-Abstract.git fix deep empty expr to render nothing --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 7746522..4fbd3a4 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -1185,8 +1185,10 @@ sub _render_op_andor { my ($self, $op, $args) = @_; return undef unless @$args; return $self->join_query_parts('', $args->[0]) if @$args == 1; + my $inner = $self->_render_op_multop($op, $args); + return undef unless defined($inner->[0]) and length($inner->[0]); return $self->join_query_parts(' ', - '(', $self->_render_op_multop($op, $args), ')' + '(', $inner, ')' ); } @@ -1210,7 +1212,7 @@ sub join_query_parts { : ((ref($_) eq 'ARRAY') ? $_ : [ $_ ]) ), @parts; return [ - $self->{join_sql_parts}->($join, map $_->[0], @final), + $self->{join_sql_parts}->($join, grep defined, map $_->[0], @final), (map @{$_}[1..$#$_], @final), ]; } diff --git a/t/02where.t b/t/02where.t index 644eca5..1b0ac92 100644 --- a/t/02where.t +++ b/t/02where.t @@ -402,7 +402,12 @@ my @handle_tests = ( where => { artistid => {} }, stmt => '', bind => [ ], - } + }, + { + where => [ -and => [ {}, [] ], -or => [ {}, [] ] ], + stmt => '', + bind => [ ], + }, ); for my $case (@handle_tests) {