From b6f3fae487344ae517deb408b5c04c4bda9f6d84 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 23 Jan 2018 23:14:39 +0100 Subject: [PATCH] fix storing food to the database --- .../info/nightscout/androidaps/db/FoodHelper.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/FoodHelper.java b/app/src/main/java/info/nightscout/androidaps/db/FoodHelper.java index 992e328532..a933c2166e 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/FoodHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/FoodHelper.java @@ -70,7 +70,7 @@ public class FoodHelper { public boolean createOrUpdate(Food food) { try { // find by NS _id - if (food._id != null) { + if (food._id != null && !food._id.equals("")) { Food old; QueryBuilder queryBuilder = getDaoFood().queryBuilder(); @@ -90,12 +90,13 @@ public class FoodHelper { } else { return false; } + } else { + getDaoFood().createOrUpdate(food); + log.debug("FOOD: New record: " + food.toString()); + scheduleFoodChange(); + return true; } } - getDaoFood().createOrUpdate(food); - log.debug("FOOD: New record: " + food.toString()); - scheduleFoodChange(); - return true; } catch (SQLException e) { log.error("Unhandled exception", e); }