in reply to DBI and variable numbers of bind parameters

One slightly more succint (perhaps "elegant" even) way of implementing this part of your second approach
my $in; $in .= '?, ' for @ins; # discard hanging comma $in =~ s/, $//;
is to say
my $in = join ', ', ('?') x @ins;
But actually I have a question on your first approach. Does it actually work? I've been trying it here, passing a string of comma separated numeric values as the bind value for a single placeholder in an IN clause, and in my case (MySQL 4.1, DBD::mysql 2.9007) it seems to just take the first value in the list. Can you post some more sample code and output to show how this works? I ask because it seems like it shouldn't work; that is, it shouldn't let you pass multiple values for a single placeholder.

Replies are listed 'Best First'.
Re^2: DBI and variable numbers of bind parameters
by friedo (Prior) on Oct 18, 2005 at 04:46 UTC
    I've been trying it here, passing a string of comma separated numeric values as the bind value for a single placeholder in an IN clause, and in my case (MySQL 4.1, DBD::mysql 2.9007) it seems to just take the first value in the list.

    Oops! You're right -- I was mistaken. Looking back, I had confused two separate pieces of code when thinking about this problem. The code that made me think of the first method actually has $in inlined right into the SQL. Obviously that's no good! I guess that pretty much answers the question, then. <Emily Litella>Nevermiiiind!</ET>

    (And I didn't write that piece, I swear. :) But I am going to fix it post-haste.)