我尝试运行此查询的 IN 运算符有问题
public Cursor getFoodToAvoid(String[] diseases){
String value="";
for(int i=0; i<diseases.length; i++){
if(i!=diseases.length-1){
value = value+diseases[i] +",";
}else{
value=value+diseases[i];
}
}
Cursor c =null;
String[] args={value};
String sql = "SELECT distinct "+FoodsTable.FOOD_NAME+", "+FoodsTable.FOOD_ENERGY_CONTENT+
","+FoodsTable.FOOD_ID+","+FoodsTable.FOOD_AMOUNT+","+FoodsTable.FOOD_CALORIES+
","+ FoodsTable.BARCODE+","+FoodsTable.FOOD_CATEGORY+
" FROM "+FoodToAvoidTable.TABLE_NAME + " , " +FoodsTable.TABLE_NAME+
" WHERE "+FoodToAvoidTable.FOOD_ID_FK+ " = "+FoodsTable.FOOD_ID + " AND " +
FoodToAvoidTable.DISEASE_ID_FK+ " IN ( ? ) ";
try{
c = db.rawQuery(sql, args);
Log.d(TAG, args[0] +" ");
}catch(Exception e){
e.printStackTrace();
}
return c;
}
但是我得到一个空光标我知道问题出在 IN 运算符上,但我无法解决。我不能使用 OR 运算符,因为数组疾病是动态的,它的大小会根据用户而变化
谢谢