Skip to content

Commit 2dc6087

Browse files
committed
Do not add empty where expressions
1 parent 3dc5ab2 commit 2dc6087

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

lib/Data/ObjectDriver/SQL.pm

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ sub add_complex_where {
171171
my $stmt = shift;
172172
my ($terms) = @_;
173173
my ($where, $bind) = $stmt->_parse_array_terms($terms);
174-
push @{ $stmt->{where} }, $where;
175-
push @{ $stmt->{bind} }, @$bind;
174+
if ($where) {
175+
push @{ $stmt->{where} }, $where;
176+
push @{ $stmt->{bind} }, @$bind;
177+
}
176178
}
177179

178180
sub _parse_array_terms {
@@ -195,18 +197,22 @@ sub _parse_array_terms {
195197
foreach my $t2 ( keys %$t ) {
196198
my ($term, $bind, $col) = $stmt->_mk_term($t2, $t->{$t2});
197199
$stmt->where_values->{$col} = $t->{$t2};
198-
push @out, "($term)";
199-
push @bind, @$bind;
200+
if ($term) {
201+
push @out, "($term)";
202+
push @bind, @$bind;
203+
}
200204
}
201-
$out .= '(' . join(" AND ", @out) . ")";
205+
$out .= '(' . join(" AND ", @out) . ")" if @out;
202206
}
203207
elsif (ref $t eq 'ARRAY') {
204208
# another array of terms to process!
205209
my ($where, $bind) = $stmt->_parse_array_terms( $t );
206-
push @bind, @$bind;
207-
$out = '(' . $where . ')';
210+
if ($where) {
211+
push @bind, @$bind;
212+
$out = '(' . $where . ')';
213+
}
208214
}
209-
push @out, (@out ? ' ' . $logic . ' ' : '') . $out;
215+
push @out, (@out ? ' ' . $logic . ' ' : '') . $out if $out;
210216
}
211217
return (join("", @out), \@bind);
212218
}

0 commit comments

Comments
 (0)