-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sql IN Statemenr #70
Comments
Afaik there is no helper which auto-expands the params for you. 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?
The text was updated successfully, but these errors were encountered: