in reply to Re: DBI bind error
in thread DBI bind error

I see what your saying. THat just brings up a host of new problems though. The input on id is variable and can be changed. Is there a good fix to get around this, or should i just split off the commas and count values then add the ? as a string?

Replies are listed 'Best First'.
Re^3: DBI bind error
by ikegami (Patriarch) on Jan 18, 2009 at 02:46 UTC
    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);