in reply to SQL prepared statements using MySQL In ()
there is no DBI/SQL-placeholder for lists (unfortunately)
==== Long answer:
Provided that the number of values is dynamic, please try converting an array, like
my @valuesForIn = (1,2,3,4,5); my $placeholders = join ',' , map {"?"} @valuesForIn; my $query = qq~ SELECT field1 FROM table1 WHERE field2 IN ($placeholders) ~; my $sth1 = $dbh->prepare($query) or die->$errstr(); $sth1->execute(@valuesForIn) or die $dbh->errstr;
(Disclaimer: Typed into mobile, hence untested)
Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery
PS there is a fancier way to avoid the map
("?") x @valuesForIn
, but I'm not sure about the precedence here. :)
please also be aware of the speed penalty of repeatedly preparing a statement for different length of lists ...
|
|---|