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);
しかし、空のカーソルを再実行します。シェルでクエリを試してみましたが、動作します。コードに実装する方法は?
編集:私はそれを行う別の方法を見つけました:
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);