From: Matt S Trout Date: Thu, 19 Sep 2019 19:16:44 +0000 (+0000) Subject: fix deep empty expr to render nothing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0536821b0ba2caca9fdc96c6f8c256f924d8a577;p=scpubgit%2FQ-Branch.git fix deep empty expr to render nothing --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 682139d..752714b 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) {