私は古いアプリをリファクタリングしています。部屋へのクエリを変更しようとするのは簡単なクエリでは簡単ですが、今はクエリ結果に応じて文字列を返すメソッドが必要ですそれを達成するために?Room Dao条件
@Query("SELECT * FROM $SHIFT_TABLE WHERE ($SHIFT_START_DATE BETWEEN :arg0.startDateTime AND :arg0.endDateTime) OR $SHIFT_END_DATE BETWEEN :arg0.startDateTime AND :arg0.endDateTime)" +
" OR (($SHIFT_START_DATE <= :arg0.startDateTime) AND ($SHIFT_END_DATE >= :arg0.endDateTime ))")
fun create(shift: Shift) {
//there is a shift at that time return shift_overlapping_with_other_shift
//shift is shorter that 1 minute return shifts_shorter_than_one_minute_are_not_recorded
//else enter the shift and return shift_was_enterd
}
編集:これは誰かがより良い方法を知っていれば、私はするために修正する必要があるいくつかのものがあります
@Query("SELECT * FROM $SHIFT_TABLE WHERE ($SHIFT_START_DATE BETWEEN :arg0.startDateTime AND :arg0.endDateTime) OR $SHIFT_END_DATE BETWEEN :arg0.startDateTime AND :arg0.endDateTime)" +
" OR (($SHIFT_START_DATE <= :arg0.startDateTime) AND ($SHIFT_END_DATE >= :arg0.endDateTime ))")
fun getShiftAtDate(shift: Shift):List<Shift>
@Insert
fun insertShift(shift: Shift)
fun create(shift: Shift):String {
//shift is shorter that 1 minute return
if (shift.totalTime == 0) {//shift is shorter that 1 minute
return MyApp.instance.resources.getString(R.string.shifts_shorter_than_one_minute_are_not_recorded)
}
//there is a shift at that time
if (!getShiftAtDate(shift).isEmpty()){
return MyApp.instance.resources.getString(R.string.shift_overlapping_with_other_shift)
}
//else enter the shift
insertShift(shift)
return MyApp.instance.resources.getString(R.string.shift_was_enterd)
}
。 – chandil03
シャンデル、私は部屋を使用する方法を知っていると私はこの記事を何度も読んだ。 – Yuval
その場合は、関数本体を作成していないはずで、create関数で戻り値の型を指定してください。それを注意深く読んで、あなたの解決策を得ます。 – chandil03