
In case that coffee machine loses connection during recording of a coffee, this coffee is added once again as a part of offlineQueue. This patch resolves this issue by checking the database for the same records before adding the new one. --- Vyřešení bugu z 18/02/2019. coffee_db.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/coffee_db.py b/coffee_db.py index 7e28f92..d21b36c 100644 --- a/coffee_db.py +++ b/coffee_db.py @@ -51,7 +51,11 @@ def add_coffee(uid, flavor, time=None): if time is None: c.execute("insert into coffees (id, flavor) values (?,?)", (uid,flavor)) else: - c.execute("insert into coffees (id, flavor, time) values (?,?,?)", (uid, flavor, time)) + res = list(c.execute("select * from coffees where id = ? and flavor = ? and time = ?", (uid, flavor, time))) + + if len(res) < 1: + c.execute("insert into coffees (id, flavor, time) values (?,?,?)", (uid, flavor, time)) + close_db(conn) def flavors(): -- 2.7.4