dwalin has asked for the wisdom of the Perl Monks concerning the following question:
Then SELECT some data:sqlite> create table foo (foo int, bar int); sqlite> insert into foo (foo, bar) values (1,1); sqlite> insert into foo (foo, bar) values (1,2); sqlite> insert into foo (foo, bar) values (1,3);
Works all right. Now I'm trying to use DBD::SQLite 1.29:sqlite> select * from foo where foo = 1 and bar in (1,2,3); 1|1 1|2 1|3
my $sth = $dbh->prepare('select * from foo where foo = $1 and bar in ($2)'); $sth->execute(1, [1,2,3]);
And this gives me null results. DBI trace shows that 2nd placeholder is bound to array all right, but no score. If I join array values in a string and pass it, no result. If I flatten the array, I get predictable error of "called with N placeholders instead of 2".
I'm kinda at loss. What else is there to try besides modifying the query?
Upd: It seems that I wasn't clear enough above: I'm not trying to stuff an array into a column, I'm trying to pass it somehow to the query so that it could be used as a set of values in standard-SQL "IN" and "NOT IN" operators.
I'm perfectly aware of query rewriting option, and this is exactly what my code does presently. I don't like this approach because it's very brittle, hence my question.
Regards,
Alex.
|
|---|