Android Question ExecQuery2

andrewmp

Member
Licensed User
Longtime User
Does someone know how to pass the parameters for this SQL ? (Col3 is int)

Dim Cursor As ResultSet
Cursor = sql1.ExecQuery2("SELECT col1 FROM table1 WHERE col3 IN (?)", Array As Int(22,21,22))

Thanks in advance
 

mc73

Well-Known Member
Licensed User
Longtime User
I understand your problem.
You have to prepare a query for each id by looping over them, or
construct your query and avoid using a prepared statement.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
rs = SQL.ExecQuery2( "SELECT * FROM table1 WHERE col1 IN (?,?,?)", Array("john","paul","ringo") ), not (?)

you need a placemarker for each element in the list.
if you don't know how many elements there will be in the list, you have to build a placeholder.
obviously, at some point you'll have to know how many elements there are, otherwise you'd never be able to formulate a query.
building the placeholder is easy: if you have 6 elements in the list, the placeholder will be (?,?,?,?,?,?). count the elements and put a "?" for each one.
separate with a comma.
your query would look something like "SELECT * FROM table1 WHERE col1 IN (" & placeholder & ")"
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I don't know how many id's I will have beforehand
If the number of IDs ( col1 in your case) changes from situation to the other, but you have a way to create and put the IDs in a list somehow, there is a way of using an ExecQuery and StringBuilder to build the IN OPERATOR clause without using the question marks and without hard coding any question marks. The key here is, if you have the ability to assemble the IDs in a list before execution. If this is the case you are trying to achieve, it is doable. I or someone else can help with the code if needed.
 
Upvote 0
Top