我想将多个参数传递给 Android 中的查询。我执行以下操作:
String final QUERY = "SELECT TA.ID FROM TAB TA LEFT JOIN PROP P ON P.ID = TA.ID LEFT JOIN LOC L ON L.ID = TA.ID LEFT JOIN TIME T ON T.ID = TA.ID WHERE (COALESCE(LONG,?) - ?) * (COALESCE(LONG,?) - ?) + (COALESCE(LAT,?) - ?) * (COALESCE(LAT,?) - ?) <=COALESCE(VALUE,0)*COALESCE(VALUE,0) AND ? BETWEEN COALESCE(BEGIN,0) AND COALESCE(END, 123456)";
String[] args= {"" + val1, "" + val2, "" + val3, "" + val4, "" + val5, "" val6, "" + val7, "" + val8, "" + val9};
cursor = db.rawQuery(QUERY,args);
但它会返回一个空游标。我在shell中尝试了查询,它有效。如何在代码中实现它?
编辑:我找到了另一种方法:
QUERY = "SELECT TA.ID FROM TAB TA LEFT JOIN PROP P ON P.ID = TA.ID LEFT JOIN LOC L ON L.ID = TA.ID LEFT JOIN TIME T ON T.ID = TA.ID WHERE (COALESCE(LONG," + val1+ " ) - " + val2 + " ) * (COALESCE(LONG," + val3 + " ) - " + val4 + " ) + (COALESCE(LAT," + val5 + " ) - " + val6 + ") * (COALESCE(LAT," + val7 + " ) - " + val8 + ") <=COALESCE(VALUE,0)*COALESCE(VALUE,0) AND" + val9 + " BETWEEN COALESCE(BEGIN,0) AND COALESCE(END, 123456)";
cursor = db.rawQuery(QUERY,null);