Re: DBI, "prepare" and "in" clauses
Posted in 2000
rboucher Would this work? Create an array @validvalues with all the valid values for name. Then: $sqlstmt = "select name, age from people where name in ("; for ($i = 0; $i < $#validvalues; $i++) { $sqlstmt += "?,"; } $sqlstmt += ")"; $sth = $dbh->prepare($sqlstmt); $sth->execute(@validvalues); HTH Sujit rboucher@my-deja.com on 02/24/2000 10:34:44 AM Please respond to rboucher@my-deja.com To: informix-list@iiug.org cc: Subject: DBI, "prepare" and "in" clauses According to the perldoc DBI page: ...Placeholders can only represent single scalar values, so this statement, for example, won't work as expected for more than one value: "select name, age from people where name in (?)" # wrong Given that, and the fact that preparing statements provides a nice performance boost, what's the best solution? I could prepare multiple statements, like these: "select name, age from people where name in (?)" "select name, age from people where name in (?,?)" "select name, age from people where name in (?,?,?)" But some of these statements can have 50-200 parameters, and this seems like a but of a hack. Any advice would be appreciated. Sent via Deja.com http://www.deja.com/ Before you buy.