diff --git a/database/impl/src/main/java/info/nightscout/database/impl/daos/BolusDao.kt b/database/impl/src/main/java/info/nightscout/database/impl/daos/BolusDao.kt index cb91fed85b..fd1c106776 100644 --- a/database/impl/src/main/java/info/nightscout/database/impl/daos/BolusDao.kt +++ b/database/impl/src/main/java/info/nightscout/database/impl/daos/BolusDao.kt @@ -63,11 +63,11 @@ internal interface BolusDao : TraceableDao { fun getBolusesIncludingInvalidFromTimeToTime(from: Long, to: Long): Single> // This query will be used with v3 to get all changed records - @Query("SELECT * FROM $TABLE_BOLUSES WHERE id > :id AND type <> :exclude AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_BOLUSES WHERE id > :id) ORDER BY id ASC") + @Query("SELECT * FROM $TABLE_BOLUSES WHERE id > :id AND pumpId IS NOT NULL AND type <> :exclude AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_BOLUSES WHERE id > :id) ORDER BY id ASC") fun getModifiedFrom(id: Long, exclude: Bolus.Type = Bolus.Type.PRIMING): Single> // for WS we need 1 record only - @Query("SELECT * FROM $TABLE_BOLUSES WHERE id > :id AND type <> :exclude ORDER BY id ASC limit 1") + @Query("SELECT * FROM $TABLE_BOLUSES WHERE id > :id AND pumpId IS NOT NULL AND type <> :exclude ORDER BY id ASC limit 1") fun getNextModifiedOrNewAfterExclude(id: Long, exclude: Bolus.Type = Bolus.Type.PRIMING): Maybe @Query("SELECT * FROM $TABLE_BOLUSES WHERE id = :referenceId") diff --git a/database/impl/src/main/java/info/nightscout/database/impl/daos/TemporaryBasalDao.kt b/database/impl/src/main/java/info/nightscout/database/impl/daos/TemporaryBasalDao.kt index 0a89476e45..373851489b 100644 --- a/database/impl/src/main/java/info/nightscout/database/impl/daos/TemporaryBasalDao.kt +++ b/database/impl/src/main/java/info/nightscout/database/impl/daos/TemporaryBasalDao.kt @@ -72,11 +72,11 @@ internal interface TemporaryBasalDao : TraceableDao { fun getLastHistoryRecord(id: Long): TemporaryBasal? // This query will be used with v3 to get all changed records - @Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_TEMPORARY_BASALS WHERE id > :id) ORDER BY id ASC") + @Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE id > :id AND pumpId IS NOT NULL AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_TEMPORARY_BASALS WHERE id > :id) ORDER BY id ASC") fun getModifiedFrom(id: Long): Single> // for WS we need 1 record only - @Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE id > :id ORDER BY id ASC limit 1") + @Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE id > :id AND pumpId IS NOT NULL ORDER BY id ASC limit 1") fun getNextModifiedOrNewAfter(id: Long): Maybe @Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE id = :referenceId")