Relational Database Manager with SQL
import sqlite3
con = sqlite3.connect("./e-commerce/e-commerce.db")
cur = con.cursor()
print("Welcome to E-commerce DB!")
print("Select action:")
print()
print("Add data to customers (1)")
print("Add data to orders (2)")
print("Add data to shipping (3)")
print("Delete data from customers (4)")
print("Delete data from orders (5)")
print("Delete data from shipping (6)")
print("Get data from customers (7)")
print("Get data from orders (8)")
print("Get data from shipping (9)")
print("Get data from products (10)")
print()
selectionPrompt = input("Selection: ")
if selectionPrompt == "1":
customerName = input("Input your name: ")
customerAge = int(input("Input your age: "))
customerAddress = input("Input your home address: ")
customerPaymentInfo = input("Enter your payment info: ")
customerEmail = input("Input your email: ")
cur.execute(f"""INSERT INTO customers(customerName,
customerAge, customerAddress, customerPaymentInfo, customerEmail)
VALUES("{customerName}", {customerAge}, "{customerAddress}", "{customerPaymentInfo}",
"{customerEmail}")""")
con.commit()
print()
print("Data has been added to the customers table!")
elif selectionPrompt == "2":
productID = int(input("Please enter your productID: "))
customerID = int(input("Please enter your customerID: "))
cur.execute(f"""INSERT INTO orders(productID, customerID)
VALUES({productID}, {customerID})""")
con.commit()
print()
print("Data has been added to the orders table!")
elif selectionPrompt == "3":
orderID = int(input("Please enter your orderID: "))
customerID = int(input("Please enter your customerID: "))
cur.execute(f"""INSERT INTO shipments(orderID, customerID)
VALUES({orderID}, {customerID})""")
con.commit()
print()
print("Data has been added to the shipments table!")
elif selectionPrompt == "4":
customerID = input("Enter a customerID: ")
cur.execute(f"""DELETE FROM customers WHERE customerID={customerID}""")
con.commit()
print()
print("Data has been deleted from the customers table!")
elif selectionPrompt == "5":
orderID = input("Enter your orderID: ")
cur.execute(f"""DELETE FROM orders WHERE orderID={orderID}""")
con.commit()
print()
print("Data has been deleted from the orders table!")
elif selectionPrompt == "6":
shippingID = input("Enter your shippingID: ")
cur.execute(f"""DELETE FROM shippings WHERE orderID={shippingID}""")
con.commit()
print()
print("Data has been deleted from the shippings table!")
elif selectionPrompt == "7":
customerID = int(input("Enter your customerID: "))
cur.execute(f"""SELECT FROM customers WHERE customerID={customerID}""")
print()
print(cur.fetchone())
Comments
Post a Comment