Open brescia123 opened 10 years ago
Afaik there is no helper which auto-expands the params for you. But you could simply do this:
Query.many(YourModel.class, "SELECT * FROM YourModel WHERE column IN (?, ?)", "value1", "value2");
Ok, but if I don't know the number of parameters I can't use this. I have to manually construct the sql query, right?
Yeah, something like this should do:
String[] params = new String[] {"value1", "value2", "value3", ...};
StringBuilder placeholder = new StringBuilder();
for (int i = 1; i <= params.length; i++) {
placeholder.append("?");
if (i < params.length) {
placeholder.append(",");
}
}
Query.many(YourModel.class, "SELECT * FROM YourModel WHERE column IN (" + placeholder.toString() + ")", params);
But maybe @emilsjolander comes with a better solution.
@jdreesen is correct, this is the best solution currently. We should maybe look into adding a helper method for this. Of the top of my head i am thinking something a long the lines of
ArrayParam param = new ArrayParam(array)
param.commas() -> "?,?,?"
param.args() -> [obj1, obj2, obj3]
How can I make a query with the IN statement?