SPUG: Turning off auto-quoting during DBI Binding.
Yitzchak Scott-Thoennes
sthoenna at efn.org
Tue Apr 8 07:32:18 PDT 2008
On Mon, Apr 07, 2008 at 08:30:35PM -0700, Stephen Blum wrote:
> How does one turn off the annoying and sometimes unneeded auto-quoting
that occurs during DBI Bindings? I have searched the net for a while
now and have found little on the subject.
>
> example:
>
> $sql = q(thrrr_id in (?));
> $sth = $dbh->prepare($sql);
> $sth->execute( q(1,2,3,4,5) );
>
> DBI executes this: thrrr_id in ('1,2,3,4,5')
> But I want to execute this: thrrr_id in (1,2,3,4,5)
>
> DBI adds quotes and I don't want them. If there is no way around this I
can forgo the performance/convenience of bindings.
There's no way around it. Either just interpolate into the query:
$ids = "1,2,3,4,5";
$sql = qq(thrrr_id in ($ids));
$sth = $dbh->prepare($sql);
$sth->execute();
or use an array and provide the appropriate number of ? instead:
@ids = (1,2,3,4,5);
$sql = 'thrrr_id in ('.join(',',('?') x @ids).')';
$sth = $dbh->prepare($sql);
$sth->execute(@ids);
More information about the spug-list
mailing list