DatabaseHelper: add getTreatmentByDate.

This commit is contained in:
Johannes Mockenhaupt 2017-10-31 19:28:32 +01:00
parent 74bbab9cf1
commit 744d24cbcf
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -680,6 +680,24 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
@Nullable
public Treatment getTreatmentByDate(long mills) {
try {
Dao<Treatment, Long> daoTreatments = getDaoTreatments();
List<Treatment> treatments;
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
Where where = queryBuilder.where();
where.eq("date", mills);
PreparedQuery<Treatment> 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<Treatment> getTreatmentDataFromTime(long mills, boolean ascending) {
try {
Dao<Treatment, Long> daoTreatments = getDaoTreatments();