From 65d201415d77d0caeacd0a463ada42478f9275ae Mon Sep 17 00:00:00 2001 From: Fabrizio Gennari Date: Thu, 30 Aug 2018 00:04:04 +0200 Subject: [PATCH 1/2] Do not generate incorrect SQL in presence of -and=>[] --- lib/SQL/Abstract.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index af8c2565..62c3f899 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -1484,13 +1484,14 @@ sub _assert_bindval_matches_bindtype { sub _join_sql_clauses { my ($self, $logic, $clauses_aref, $bind_aref) = @_; - if (@$clauses_aref > 1) { + my @clauses_aref = grep {$_} @$clauses_aref; + if (@clauses_aref > 1) { my $join = " " . $self->_sqlcase($logic) . " "; - my $sql = '( ' . join($join, @$clauses_aref) . ' )'; + my $sql = '( ' . join($join, @clauses_aref) . ' )'; return ($sql, @$bind_aref); } - elsif (@$clauses_aref) { - return ($clauses_aref->[0], @$bind_aref); # no parentheses + elsif (@clauses_aref) { + return ($clauses_aref[0], @$bind_aref); # no parentheses } else { return (); # if no SQL, ignore @$bind_aref From 3e759b172be1eff4fd73a5f2fc9c04027f12eead Mon Sep 17 00:00:00 2001 From: Fabrizio Gennari Date: Tue, 5 Feb 2019 23:43:25 +0100 Subject: [PATCH 2/2] Add a test about generated SQL in presence of "-and=>[]" --- t/02where.t | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/02where.t b/t/02where.t index 229770b6..d2ab36db 100644 --- a/t/02where.t +++ b/t/02where.t @@ -391,6 +391,11 @@ my @handle_tests = ( stmt => " WHERE ( 0 ) ", bind => [ ], }, + { + where => { -and => [], -or => [ a => 1 ] }, + stmt => " WHERE ( a = ? ) ", + bind => [ 1 ], + }, ); for my $case (@handle_tests) {