
On Tue, Feb 26, 2019 at 01:58:42PM +0100, Jaroslav Klapalek wrote:
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 using 'EXISTS' condition. --- Podle návrhu od Jirky: Nová verze, která využívá pouze jeden dotaz.
Za me dobry. jiri
coffee_db.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/coffee_db.py b/coffee_db.py index 7e28f92..84b5ca0 100644 --- a/coffee_db.py +++ b/coffee_db.py @@ -51,7 +51,12 @@ 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)) + c.execute(""" + insert into coffees (id, flavor, time) + select ?, ?, ? + where not exists(select * from coffees where id = ? and flavor = ? and time = ?) + """, (uid, flavor, time, uid, flavor, time)) + close_db(conn)
def flavors(): -- 2.7.4
_______________________________________________ Coffee mailing list Coffee@rtime.felk.cvut.cz https://rtime.felk.cvut.cz/mailman/listinfo/coffee