From 744d24cbcf9111f725f1726a838e006a7b0914d2 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 31 Oct 2017 19:28:32 +0100 Subject: [PATCH] DatabaseHelper: add getTreatmentByDate. --- .../androidaps/db/DatabaseHelper.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 2767f7611a..21ceea6950 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -680,6 +680,24 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } + @Nullable + public Treatment getTreatmentByDate(long mills) { + try { + Dao daoTreatments = getDaoTreatments(); + List treatments; + QueryBuilder queryBuilder = daoTreatments.queryBuilder(); + Where where = queryBuilder.where(); + where.eq("date", mills); + PreparedQuery preparedQuery = queryBuilder.prepare(); + treatments = daoTreatments.query(preparedQuery); + // date is unique + return treatments.isEmpty() ? null : treatments.get(0); + } catch (SQLException e) { + log.error("Unhandled exception", e); + return null; + } + } + public List getTreatmentDataFromTime(long mills, boolean ascending) { try { Dao daoTreatments = getDaoTreatments();