in reply to DBI and variable numbers of bind parameters

The second way is fine i think.. personally, i generally write it like this (easily extendable to handle conditional building of the statement):
my $sql = "SELECT foo FROM Bar WHERE 1=1"; my @bind; $sql .= " AND baz in ( " . join(',', map {'?'} @ins) . ") "; push @bind, @ins; $dbh->selectall_arrayref($sql, {}, @bind);
Another way is to use something like SQL::Abstract:
use SQL::Abstract; my $SA = SQL::Abstract->new; my ($sql, @bind) = $SA->select('Bar', ['foo'], {baz => \@ins}); $dbh->selectall_arrayref($sql, {}, @bind);

Replies are listed 'Best First'.
Re^2: DBI and variable numbers of bind parameters
by diotalevi (Canon) on Oct 18, 2005 at 15:10 UTC

    Between ( '?' ) x @ins and map { '?' } @ins, the first is more efficient. There's no loop - it just creates the right number of elements in place.