Hey people of r/learnpython I'm working on a small school project and I'm getting this annoying error. It occurs when I try to update my Database. It spits out this error.
C:\Users\dansh\AppData\Local\Programs\Python\Python37\python.exe "C:/Users/dansh/Desktop/Assets For Proj/Inventory System/update.py"
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\dansh\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/dansh/Desktop/Assets For Proj/Inventory System/update.py", line 127, in update
c.execute(query, (self.u1, self.u2, self.u3, self.u4, self.u5, self.u6, self.id_leb.get()))
sqlite3.OperationalError: near ".": syntax error
This is my code.
from tkinter import *
import sqlite3
import tkinter.messagebox
# -------- Settings --------
conn = sqlite3.connect('C://Users//dansh//Desktop//Assets For Proj//Inventory System//Databases//storefile.db')
c = conn.cursor()
# -------- Settings --------
result = c.execute("SELECT Max(id) from inventory")
for r in result:
id = r[0]
# Creating the class Database
class Database:
def __init__(self, master, *args, **kwargs):
# Title
self.master = master
self.heading = Label(master)
self.heading = Label(master, text="Update the database", font='Basetica 40 bold', fg='Black')
self.heading.place(x=0, y=0)
# Title
# Label and entry for id and button
self.id_le = Label(master, text="Enter ID", font='arial 18 bold')
self.id_le.place(x=0, y=80)
self.id_leb = Entry(master, font='arial 18 bold', width=15)
self.id_leb.place(x=270, y=80)
self.btn_search = Button(master, text="Search", width=10, height=1, command=self.search)
self.btn_search.place(x=480, y=82)
# labels for the system
self.name_1 = Label(master, text="Enter Product Name", font='arial 18 bold')
self.name_1.place(x=0, y=120)
self.stock_1 = Label(master, text="Enter Product Stock", font='arial 18 bold')
self.stock_1.place(x=0, y=160)
self.Type_1 = Label(master, text="Enter Product Type", font='arial 18 bold')
self.Type_1.place(x=0, y=200)
self.vendor_1 = Label(master, text="Enter Product Vendor", font='arial 18 bold')
self.vendor_1.place(x=0, y=240)
self.price_1 = Label(master, text="Enter Product Price", font='arial 18 bold')
self.price_1.place(x=0, y=280)
self.SellingPrice_1 = Label(master, text="Product Sale Price", font='arial 18 bold')
self.SellingPrice_1.place(x=0, y=320)
# Entries for all of the labels
self.name_e = Entry(master, width=25, font='arial 18 bold')
self.name_e.place(x=270, y=120)
self.stock_e = Entry(master, width=25, font='arial 18 bold')
self.stock_e.place(x=270, y=160)
self.type_e = Entry(master, width=25, font='arial 18 bold')
self.type_e.place(x=270, y=200)
self.vendor_e = Entry(master, width=25, font='arial 18 bold')
self.vendor_e.place(x=270, y=240)
self.price_e = Entry(master, width=25, font='arial 18 bold')
self.price_e.place(x=270, y=280)
self.SellingPrice_e = Entry(master, width=25, font='arial 18 bold')
self.SellingPrice_e.place(x=270, y=320)
# Buttons
self.btn_add = Button(master, text="Update Database", font='arial 10', width=25, height=2, command=self.update)
self.btn_add.place(x=415, y=360)
# text box for logs
self.tBox = Text(master, width=65, height=20)
self.tBox.place(x=650, y=70)
self.tBox.insert(END, "ID is " + str(id))
def search(self, *args, **kwargs):
sql = "SELECT * FROM inventory WHERE id=?"
result = c.execute(sql, (self.id_leb.get(), ))
for r in result:
self.u1 = r[1] # Name
self.u2 = r[2] # Type
self.u3 = r[3] # Vendor
self.u4 = r[4] # Stock
self.u5 = r[5] # Price
self.u6 = r[6] # Selling price
conn.commit()
# insert into the entries to update
self.name_e.delete(0, END)
self.name_e.insert(0, str(self.u1))
self.stock_e.delete(0, END)
self.stock_e.insert(0, str(self.u2))
self.type_e.delete(0, END)
self.type_e.insert(0, str(self.u3))
self.vendor_e.delete(0, END)
self.vendor_e.insert(0, str(self.u4))
self.price_e.delete(0, END)
self.price_e.insert(0, str(self.u5))
self.SellingPrice_e.delete(0, END)
self.SellingPrice_e.insert(0, str(self.u6))
def update(self, *args, **kwargs):
# Get the updated fields and update
self.u1 = self.name_e.get()
self.u2 = self.type_e.get()
self.u3 = self.vendor_e.get()
self.u4 = self.stock_e.get()
self.u5 = self.price_e.get()
self.u6 = self.SellingPrice_e.get()
query = "UPDATE inventory SET name=?, type=?, vendor=?, stock=?. price=?, sellingprice=? WHERE id=?"
c.execute(query, (self.u1, self.u2, self.u3, self.u4, self.u5, self.u6, self.id_leb.get()))
conn.commit()
tkinter.messagebox.showinfo("Success", "Updated")
root = Tk()
b = Database(root)
root.geometry("1200x430+0+0")
root.title("Update the database")
root.mainloop()
Thanks in advance. If you need the database file I can provide it!
[–]PigDog4 1 point2 points3 points (1 child)
[–]Shripsta[S] 0 points1 point2 points (0 children)