You didn't say what errors you get, but from your code it looks like you glue several values together, and treat that as a single argument. That will lead the db to look for the whole string in each row. You need to have a placeholder for each value of argument to IN(), then feed your array as-is to the execute method. You could make an $sth for too many placeholders, and pad the arguments with undef. That would be suitable for a non-null column.
my $plch = join ', ', ('?') x @values; my $sql = <<END_SQL; SELECT COUNT(*) FROM some_table WHERE some_column IN ( $pclh ) END_SQL my $sth = $dbh->prepare_cached($sql) || die; $sth->execute(@values) || die; while ($sth->fetch) { # Do stuff } $sth->finish || die;
After Compline,
Zaxo
In reply to Re: DBI question with placeholders and IN
by Zaxo
in thread DBI question with placeholders and IN
by dragonchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |