
Aha, netušil jsem, že něco takového existuje. (Narazil jsem jen na 'INSERT OR IGNORE'.) Přepíšu a pošlu. J. Dne 26. 02. 19 v 7:08 Jiri Vlasak napsal(a):
On Mon, Feb 25, 2019 at 03:37:52PM +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 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)) Vyřešil bych to možná rovnou SQL dotazem viz https://stackoverflow.com/questions/19337029/insert-if-not-exists-statement-...
jiri
+ close_db(conn)
def flavors(): -- 2.7.4
_______________________________________________ Coffee mailing list Coffee@rtime.felk.cvut.cz https://rtime.felk.cvut.cz/mailman/listinfo/coffee