Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4
Source Code:
File Name: - Grocery Management System
import mysql.connector as c con = c.connect(host="localhost",user = "root", passwd ="123sss#feb", database = "Grocery_Retailer") cursor = con.cursor( ) cursor.execute("create table Food_Items( Product varchar(20) primary key, Price int(20), Mfg date not null, Exp date not null)") print("The table is created successfully.") while True : print("Press 1 for inserting the data in database.") print("Press 2 for deleting the data from database.") print("Press 3 for modifying the data in database.") print("Press 4 for the searching data in database.") print("Press 5 for selecting the data from database.") print("Press 6 for exiting database program.") ch = input("Enter the choice :") if(ch == "1") : a = input("Enter the product:") b = int(input("Enter the price:")) c = input("Enter the mfg:") d = input("Enter the exp:") query1 = "Insert into Food_Items values(%s,%s,%s, %s)" values1 = (a, b, c, d) cursor.execute(query1,values1) con.commit( ) print("The data successfully inserted.") if(ch == "6") : break if(ch == "2") : query2 = input("Enter the product name to delete from database:") sql1 = "Delete from Food_Items where Product = %s" val1 = (query2,) cursor.execute(sql1,val1) con.commit( ) print("The data is deleted successfully from database.") print("The updated record row in database.",cursor.rowcount) cursor.execute("select * from Food_Items") records1 = cursor.fetchall( ) for i in records1 : print( i ) print("The updated record is displayed.") if(ch == "3") : query3 = input("Enter the Product name to modify from database:") query4 = int(input("Enter the price to modify in database:")) sql2 = "Update Food_Items set Price = %s where Product = %s" val2 = (query4,query3) cursor.execute(sql2,val2) con.commit( ) print("The data is modified successfully.") print("The modified record",cursor.rowcount) cursor.execute("select * from Food_Items") records2 = cursor.fetchall( ) for i in records2 : print( i ) print("The modified record is displayed.") if(ch == "4") : query5 = input("Enter the product name you want to search:") sql3 = "Select * from Food_Items where Product = %s" val3 = (query5,) cursor.execute(sql3,val3) records3 = cursor.fetchall( ) for i in records3 : print( i ) print("The searching is successfully finished.") print("The searched record",cursor.rowcount) if(ch == "5") : query6 = input("Enter the price name you want to select:") sql4 = "Select * from Food_Items where Price = %s" val4 = (query6,) cursor.execute(sql4,val4) records4 = cursor.fetchall( ) for i in records4 : print( i ) print("The selecting is successfully finished.") print("The selected record",cursor.rowcount)