-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_functions.py
74 lines (49 loc) · 1.49 KB
/
menu_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pymysql
import datetime
from prettytable import PrettyTable
# function to add new dish to menu
def add_menu_to_database(dish, price):
db = pymysql.connect("localhost", "root", "uttu8449", "DISHES_PRICES")
cursor = db.cursor()
sql = f"""INSERT INTO PRICE_LIST(DISHES, PRICE)
VALUES ('{dish}', {price})
"""
try:
cursor.execute(sql)
db.commit()
message = "done"
except:
db.rollback()
message = "error"
db.close()
return message
# function to edit menu item
def edit_menu_item_in_database(dish, price):
db = pymysql.connect("localhost", "root", "uttu8449", "DISHES_PRICES")
cursor = db.cursor()
sql = f"""UPDATE PRICE_LIST SET PRICE = {price} WHERE DISHES = '{dish}';
"""
try:
cursor.execute(sql)
db.commit()
message = "done"
except:
db.rollback()
message = "error"
db.close()
return message
# function to delete menu item
def delete_menu_item_from_database(dish):
db = pymysql.connect("localhost", "root", "uttu8449", "DISHES_PRICES")
cursor = db.cursor()
sql = f"""DELETE FROM PRICE_LIST WHERE DISHES = '{dish}';
"""
try:
cursor.execute(sql)
db.commit()
message = "done"
except:
db.rollback()
message = "error"
db.close()
return message