Subject: | broken for NULL values |
When I try to execute a statement like:
my $count = QD1::Identifier->count_search(
coord_id => 1,
primary => undef,
);
it fails with the message:
DBD::mysql::st execute failed: called with 2 bind variables
when 1 are needed [for Statement "SELECT COUNT(*)
FROM identifiers
WHERE coord_id = ? AND primary_id IS NULL
because although CDBI-P-CS correctly recognizes the undef, it still
passes it to the database. The following patch corrects the problem:
--- Class/DBI/Plugin/CountSearch-1.02.pm
+++ Class/DBI/Plugin/CountSearch.pm
@@ -81,6 +81,8 @@
defined($frag) && $frag ne '' and
$frag = " WHERE $frag";
+ @vals = grep { defined $_ } @vals;
+
return $class->sql_count_search($frag)->select_val(@vals);
};