Phil Lawrence on 20 Sep 2004 20:32:54 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: sql, dbi, placeholders and 'in'


Phil Lawrence wrote:
IIRC, you can just do this:
my $sth = $dbh->prepare(<<'');
  SELECT fields
    FROM table
   WHERE product IN (?)
     AND document IN (?)

then map the bind values into a single string like this:
   q{'a','b','c'}
and execute as normal.

No, wait, I don't think that's right. Here's a relevant piece of code from SQL::Snippet, and I see that I'm *not* using one ? for everything.


# 'qnd' as in 'quote and delimit'
sub qnd {
    ...

    my $list = (ref $_[0]) ? $_[0] : [ $_[0] ];
    return join ',' => map  {
                                $_ eq '?'   # don't quote bind vals
                                ? $_
                                :
                                    $_ eq '\?'  # unescape and quote
                                                # literal ?
                                    ? $self->dbh->quote( '?' )
                                    : $self->dbh->quote( $_ )
                            }
                            @$list;
}


I must have been remembering times when I would not use binds, but rather prepare the statement with all the IN values hard-coded.


Sorry for the misremembering,
Phil
-
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**