From 0e5bc28930d8a16da13cc5362ad84414f0c31290 Mon Sep 17 00:00:00 2001 From: Eduard Date: Fri, 23 May 2025 15:41:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9=20=D0=B2=20?= =?UTF-8?q?=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/db.py | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/db/db.py b/db/db.py index d9e15b4..836ad41 100644 --- a/db/db.py +++ b/db/db.py @@ -48,9 +48,25 @@ class Database: act.project_id, ) ) + except sq.IntegrityError: + cur.execute( + """UPDATE activities + SET description = ?, time_spent = ?, date_start = ?, date_end = ?, is_tracked = ?, vetro_project_id = ?, tag_id = ?, project_id = ? + WHERE id = ?""", + ( + act.description, + act.time_spent, + act.date_start, + act.date_end, + act.is_tracked, + act.vetro_project_id, + act.tag_id, + act.project_id, + act.id, + ) + ) + finally: self.con.commit() - except Exception: - pass if not is_updated: logging.info("База данных устарела. Рекомендуем обновить с помощью флага -i [--init-db]") @@ -72,7 +88,7 @@ class Database: ) ) self.con.commit() - except Exception: + except sq.IntegrityError: pass @@ -81,9 +97,15 @@ class Database: for tag in tags: try: cur.execute("INSERT INTO tags VALUES(?, ?)",(tag.id,tag.title)) + except sq.IntegrityError: + cur.execute( + """UPDATE tags + SET title = ? + WHERE id = ?""", + (tag.title, tag.id) + ) + finally: self.con.commit() - except Exception: - pass def insert_vetro_projects(self, vetro_projects: list[VetroProject]): @@ -91,15 +113,27 @@ class Database: for vetro_project in vetro_projects: try: cur.execute("INSERT INTO vetro_projects VALUES(?, ?)", (vetro_project.id, vetro_project.title)) + except sq.IntegrityError: + cur.execute(""" + UPDATE vetro_projects + SET title = ? + WHERE id = ?""", + (vetro_project.title, vetro_project.id) + ) + finally: self.con.commit() - except Exception: - pass def insert_activity_types(self, activity_types: list[ActivityType]): cur = self.con.cursor() for activity_type in activity_types: try: cur.execute("INSERT INTO activity_types VALUES(?, ?)", (activity_type.id, activity_type.title)) + except sq.IntegrityError: + cur.execute(""" + UPDATE activity_types + SET title = ? + WHERE id = ?""", + (activity_type.title, activity_type.id) + ) + finally: self.con.commit() - except Exception: - pass