mirror of
https://github.com/ada-dmitry/lab6.git
synced 2026-09-24 01:10:15 +00:00
0.2
This commit is contained in:
Binary file not shown.
@@ -38,14 +38,6 @@ class DbTable:
|
||||
cur.execute(sql)
|
||||
self.dbconn.conn.commit()
|
||||
return
|
||||
|
||||
def delete(self, val):
|
||||
sql = "DELETE FROM " + self.table_name()
|
||||
sql += " WHERE " + "".join(self.column_names_without_id())
|
||||
sql += "=" + "'" + "".join(val) + "';"
|
||||
cur = self.dbconn.conn.cursor()
|
||||
cur.execute(sql)
|
||||
self.dbconn.conn.commit()
|
||||
|
||||
def drop(self):
|
||||
sql = "DROP TABLE IF EXISTS " + self.table_name()
|
||||
@@ -66,7 +58,6 @@ class DbTable:
|
||||
cur = self.dbconn.conn.cursor()
|
||||
try:
|
||||
cur.execute(sql)
|
||||
self.dbconn.conn.commit()
|
||||
except psycopg2.errors.UniqueViolation:
|
||||
self.dbconn.conn.rollback()
|
||||
return
|
||||
|
||||
@@ -138,11 +138,11 @@ class Main:
|
||||
if self.cath_id == -1:
|
||||
while True:
|
||||
name = input("Укажите название категории для вывода блюд (0 - отмена):")
|
||||
while len(name.strip()) == 0:
|
||||
while len(name.strip()) == '':
|
||||
name = input("Пустая строка. Повторите ввод! Укажите название категории для вывода блюд (0 - отмена):")
|
||||
if name == "0":
|
||||
return "1"
|
||||
cath = CathTable().find_by_position(int(name))
|
||||
cath = CathTable().find_by_name(name)
|
||||
if not cath:
|
||||
print("Введено неверное название!")
|
||||
else:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+19
-8
@@ -13,14 +13,25 @@ class CathTable(DbTable):
|
||||
def table_constraints(self):
|
||||
return ['CONSTRAINT "Name" UNIQUE (cath_name)']
|
||||
|
||||
|
||||
def find_by_position(self, num):
|
||||
|
||||
sql = "SELECT * FROM " + self.table_name()
|
||||
sql += " ORDER BY "
|
||||
sql += ", ".join(self.primary_key())
|
||||
sql += " LIMIT 1 OFFSET %(offset)s"
|
||||
def delete(self, val):
|
||||
sql = "DELETE FROM " + self.table_name()
|
||||
sql += " WHERE " + "".join(self.column_names_without_id())
|
||||
sql += "=" + "'" + "".join(val) + "';"
|
||||
cur = self.dbconn.conn.cursor()
|
||||
cur.execute(sql, {"offset": num - 1})
|
||||
cur.execute(sql)
|
||||
self.dbconn.conn.commit()
|
||||
|
||||
def find_by_name(self, name):
|
||||
cur = self.dbconn.conn.cursor()
|
||||
|
||||
sql_sel = "SELECT id FROM " + self.table_name()
|
||||
sql_sel += " WHERE cath_name = " + "'" + name + "'" + ";"
|
||||
cur.execute(sql_sel)
|
||||
# sql = "SELECT * FROM " + self.table_name()
|
||||
# sql += " ORDER BY "
|
||||
# sql += ", ".join(self.primary_key())
|
||||
# sql += " LIMIT 1 OFFSET %(offset)s"
|
||||
# cur.execute(sql, {"offset": num - 1})
|
||||
# print(cur)
|
||||
return cur.fetchone()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user