-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder_functions.py
51 lines (34 loc) · 1.19 KB
/
order_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
import pymysql
from prettytable import PrettyTable
import datetime
# function to add order details to database
def add_order_details_to_database(name, date, total_paid):
db = pymysql.connect("localhost", "root", "uttu8449", "DISHES_PRICES")
cursor = db.cursor()
sql = f"""INSERT INTO ORDERS(NAME, DATE, TOTAL_PAID)
VALUES ('{name}', '{date}', {total_paid})
"""
try:
cursor.execute(sql)
db.commit()
message = "done"
except:
db.rollback()
message = "error"
db.close()
return message
# function to get details from database
def get_user_details_from_database(name):
db = pymysql.connect("localhost", "root", "uttu8449", "DISHES_PRICES")
cursor = db.cursor()
sql = f"SELECT DATE, TOTAL_PAID, ID FROM ORDERS WHERE NAME = '{name}'"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
date = row[0]
total_price = row[1]
order_id = row[2]
table = PrettyTable()
table.field_names = ["Order ID", "Date", "Total"]
table.add_row([order_id, date, total_price])
print(table)