diff --git a/__pycache__/dbtable.cpython-311.pyc b/__pycache__/dbtable.cpython-311.pyc index 5bf930c..17f5303 100644 Binary files a/__pycache__/dbtable.cpython-311.pyc and b/__pycache__/dbtable.cpython-311.pyc differ diff --git a/dbtable.py b/dbtable.py index 62d7719..1d08c37 100644 --- a/dbtable.py +++ b/dbtable.py @@ -64,8 +64,11 @@ class DbTable: sql += ", ".join(self.column_names_without_id()) + ") VALUES(" sql += ", ".join(vals) + ")" cur = self.dbconn.conn.cursor() - cur.execute(sql) - self.dbconn.conn.commit() + try: + cur.execute(sql) + self.dbconn.conn.commit() + except psycopg2.errors.UniqueViolation: + self.dbconn.conn.rollback() return def first(self): diff --git a/main.py b/main.py index 124728b..2a068b2 100644 --- a/main.py +++ b/main.py @@ -117,7 +117,7 @@ class Main: else: return next_step - def show_add_cath(self): + def add_cath(self): data = [] data.append(input("Введите название (1 - отмена): ").strip()) if data[0] == "1": @@ -131,7 +131,7 @@ class Main: data[0] = input("Название не может быть пустым! Введите название заново (1 - отмена):").strip() if data[0] == "1": return - CathTable().insert_one(data) + CathTable().insert_one(data) return def show_dish_in_cath(self): @@ -178,7 +178,7 @@ class Main: elif current_menu == "2": self.show_main_menu() elif current_menu == "3": - self.show_add_cath() + self.add_cath() current_menu = "1" print("До свидания!") return diff --git a/tables/__pycache__/cath_table.cpython-311.pyc b/tables/__pycache__/cath_table.cpython-311.pyc index 4e94321..d8e8f0f 100644 Binary files a/tables/__pycache__/cath_table.cpython-311.pyc and b/tables/__pycache__/cath_table.cpython-311.pyc differ