Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not generate incorrect SQL in presence of -and=>[] #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/SQL/Abstract.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions t/02where.t
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down