in reply to Re^2: DBI bind error
in thread DBI bind error
my @ids = ( 1, 2 ); my $value_lookup_sth = $dbh->prepare(" SELECT value WHERE id IN (" . join(',', ('?') x @ids ) . ") "); $value_lookup_sth->execute(@ids) or debug($DBI::errstr);
or
sub plist { '(' . join( ',', ('?') x $_[0] ) . ')' } my @ids = ( 1, 2 ); my $value_lookup_sth = $dbh->prepare(" SELECT value WHERE id IN ".plist(0+@ids)." "); $value_lookup_sth->execute(@ids) or debug($DBI::errstr);
or if you're particularly silly
{ package My::plist; use Tie::Array; our @ISA = 'Tie::Array'; sub TIEARRAY { bless [], shift } sub FETCH { '(' . join( ',', ('?') x $_[1] ) . ')' } } tie my @plist, 'My::plist'; my @ids = ( 1, 2 ); my $value_lookup_sth = $dbh->prepare(" SELECT value WHERE id IN $plist[@ids] "); $value_lookup_sth->execute(@ids) or debug($DBI::errstr);
|
|---|