I am working on rails 3 and sqlite db.
Using a IN query.
Currently passing an string variable of items to IN query.
But While executing that query it takes ” so it’s not working.
How to get over this situation?
Here is my code
items = ""
items << "#{@invitation_user1.id}" << "," << "#{@invitation_user2.id}" << "," << "#{@user1.id}" << "," << "#{@user2.id}" << "," << "#{@user2.id}" << "," << "#{@profile1.id}" << "," << "#{@profile2.id}"
@activities = Version.where("item_id IN (?)","#{items}")
Tried items.to_i, items.to_s but didn’t work.
In log i can see this.
SELECT "versions".* FROM "versions" WHERE (item_id IN ('19,20,4,1,1,4,1'))
But all i need is
SELECT "versions".* FROM "versions" WHERE (item_id IN (19,20,4,1,1,4,1))
You can just pass an array in. Rails is clever enough to to the right thing with it:
This is vastly preferred over your variant, as Rails properly handles escaping of all passed values for the used database adapter.