in reply to DBI question with placeholders and IN
Well, if you're using the prepared statement only once, it's not clear how much benefit you're getting from it. Nevertheless, if you want to do it that way, you need as many placeholders as values:
my $sql = qq{ SELECT COUNT(*) FROM some_table WHERE some_column IN (} . join(',', (('?') x @values)) . ")";
To me the "better" way would be to prepare the statement once and execute in a loop:
But it sounds like you've already thought of that.my $sql = <<END_SQL; SELECT COUNT(*) FROM some_table WHERE some_column = ? END_SQL my $sth = $dbh->prepare_cached($sql) || die; foreach my $value (@values) { $sth->execute($value); while ($sth->fetch) { # etc.
HTH
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: DBI question with placeholders and IN
by diotalevi (Canon) on Sep 30, 2002 at 22:34 UTC | |
by VSarkiss (Monsignor) on Oct 01, 2002 at 02:17 UTC | |
by rdfield (Priest) on Oct 01, 2002 at 08:03 UTC | |
by htoug (Deacon) on Oct 01, 2002 at 10:46 UTC |