fix(unique)_func_insert

This commit is contained in:
ada-dmitry
2024-04-28 13:09:24 +03:00
parent 57de47d41a
commit ae3cbeed26
4 changed files with 8 additions and 5 deletions
Binary file not shown.
+5 -2
View File
@@ -64,8 +64,11 @@ class DbTable:
sql += ", ".join(self.column_names_without_id()) + ") VALUES(" sql += ", ".join(self.column_names_without_id()) + ") VALUES("
sql += ", ".join(vals) + ")" sql += ", ".join(vals) + ")"
cur = self.dbconn.conn.cursor() cur = self.dbconn.conn.cursor()
cur.execute(sql) try:
self.dbconn.conn.commit() cur.execute(sql)
self.dbconn.conn.commit()
except psycopg2.errors.UniqueViolation:
self.dbconn.conn.rollback()
return return
def first(self): def first(self):
+3 -3
View File
@@ -117,7 +117,7 @@ class Main:
else: else:
return next_step return next_step
def show_add_cath(self): def add_cath(self):
data = [] data = []
data.append(input("Введите название (1 - отмена): ").strip()) data.append(input("Введите название (1 - отмена): ").strip())
if data[0] == "1": if data[0] == "1":
@@ -131,7 +131,7 @@ class Main:
data[0] = input("Название не может быть пустым! Введите название заново (1 - отмена):").strip() data[0] = input("Название не может быть пустым! Введите название заново (1 - отмена):").strip()
if data[0] == "1": if data[0] == "1":
return return
CathTable().insert_one(data) CathTable().insert_one(data)
return return
def show_dish_in_cath(self): def show_dish_in_cath(self):
@@ -178,7 +178,7 @@ class Main:
elif current_menu == "2": elif current_menu == "2":
self.show_main_menu() self.show_main_menu()
elif current_menu == "3": elif current_menu == "3":
self.show_add_cath() self.add_cath()
current_menu = "1" current_menu = "1"
print("До свидания!") print("До свидания!")
return return
Binary file not shown.