I want to search a folder structure represented in a database. I'm
using the ID and Parent columns model, and would like to be able to
search a folder's subfolders as well as teh folder itself.
To do this I'm getting a list of all the subfolders with a recursive
function and building them into a CSV list of IDs. Example output:
472,944,925,931 ,938,1692,1005, 1036,1046,1051, 1042,1816,1819, 921
I then want to do a select against the list using an IN clause. I'm
using PDO and prepared statements. The query would look something
like:
SELECT * FROM items where someValue = ? AND parent IN (?);
I execute () this statement with some search value as the first item
in the array I feed into the execute method, and my CSV list of IDs as
the second value. However, this doesn't work. It seems that the list
I'm feeding in is getting wrapped in quotes, and that's causing
Postgres to evaluate my list as a string instead of a list of
integers.
Warning: PDOStatement::e xecute() [function.PDOSta tement-execute]:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input
syntax for integer:
"472,944,925,93 1,938,1692,1005 ,1036,1046,1051 ,1042,1816,1819 ,921"
If i hard-code these values into the query I get the expected results,
but not if I try to put them in via the prepared statement
mechanism.
Can anybody help with a solution to this?
using the ID and Parent columns model, and would like to be able to
search a folder's subfolders as well as teh folder itself.
To do this I'm getting a list of all the subfolders with a recursive
function and building them into a CSV list of IDs. Example output:
472,944,925,931 ,938,1692,1005, 1036,1046,1051, 1042,1816,1819, 921
I then want to do a select against the list using an IN clause. I'm
using PDO and prepared statements. The query would look something
like:
SELECT * FROM items where someValue = ? AND parent IN (?);
I execute () this statement with some search value as the first item
in the array I feed into the execute method, and my CSV list of IDs as
the second value. However, this doesn't work. It seems that the list
I'm feeding in is getting wrapped in quotes, and that's causing
Postgres to evaluate my list as a string instead of a list of
integers.
Warning: PDOStatement::e xecute() [function.PDOSta tement-execute]:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input
syntax for integer:
"472,944,925,93 1,938,1692,1005 ,1036,1046,1051 ,1042,1816,1819 ,921"
If i hard-code these values into the query I get the expected results,
but not if I try to put them in via the prepared statement
mechanism.
Can anybody help with a solution to this?
Comment