Let's consider below function,
data class ModelData(var id: String?, var name: String?) {
}
fun loadData(ids: List<String>): List<ModelData> {
// Here, I have to return list of model data which matches with ids
}
I can do it with a loop which seems very inefficient.
fun loadData(ids: List<String>): List<ModelData> {
val list = List<ModelData>
val selection = DBKeys.MODEL_ID + " LIKE ?"
val selectionArgs = arrayOf<String>("")
for (id in ids) {
val selectionArg = arrayOf<String>(id)
val cursor = DBManager.query(TABLE_RECORD, selection, selectionArgs, null, null, null)
// prepare model 'data' from cursor
list.add(data)
}
return list
}
I wonder is there any other efficient way? It would be better if there were SQLite selection query with contains operation.
Update
From the suggested post by ADM, I found example,
String[] args = new String[]{A,B} // if A, B are variables
String[] args = new String[]{"A","B"}
Cursor cur = db.query("tab1", null, "name in (?,?)", args, null, null, null);
I wonder if the variables are from list, is there any way to prepare sanitized input it without using loop?