From fde04b87187a899c7d6ede656b19c8bb91705511 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Wed, 14 Jun 2023 14:17:03 +0200 Subject: [PATCH] Fix SQL creation error when ending active timer fixes #8 #9 --- polypomo | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/polypomo b/polypomo index 678aa24..88888f6 100755 --- a/polypomo +++ b/polypomo @@ -151,21 +151,22 @@ class Status: self.timer = Timer(self.worktime) def save(self): - with setup_conn(self.saveto) as conn: - if self.active: - conn.execute( - "INSERT INTO sessions VALUES (date('now'), time('now'), NULL)" - ) - else: - conn.execute( - """UPDATE sessions - SET stop = time('now') - WHERE start IN ( - SELECT start FROM sessions - ORDER BY start DESC - LIMIT 1) - """ - ) + if self.saveto: + with setup_conn(self.saveto) as conn: + if self.active: + conn.execute( + "INSERT INTO sessions VALUES (date('now'), time('now'), NULL)" + ) + else: + conn.execute( + """UPDATE sessions + SET stop = time('now') + WHERE start IN ( + SELECT start FROM sessions + ORDER BY start DESC + LIMIT 1) + """ + ) @contextmanager