sqlite3.OperationalError:“。”附近:语法错误

时间:2019-10-09 15:11:22

标签: python-3.x sqlite tkinter

sqlite3.OperationalError:“。”附近:语法错误

在我尝试填写表格时出现上述错误。

终端:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\username\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "c:\Users\username\Desktop\Store Accounting Software\add_to_dy.py", line 64, in get_items
    c.execute(sql, (self.name, self.Stock,self.CP, self.SP, self.Total_CP, self.Total_SP, self.Assumed_Profits, self.Vendor, self.Vendor_no))
sqlite3.OperationalError: near ".": syntax error

我在这里查找了所有类似的问题,但是找不到解决方案。这是源代码,不胜感激

from tkinter import *

import sqlite3

import tkinter.messagebox

conn = sqlite3.connect(r"C:\Users\AAJU\Desktop\Store Accounting 

Software\Database\store.db")

c = conn.cursor()

class Database:

    def __init__ (self, master, *args, **kwargs):

        self.master = master
        self.heading = Label(master, text = "Add to the database", font=('arial 40 bold'), fg='steelblue')
        self.heading.place(x=400, y=0)        
        self.name_l = Label(master, text="Enter Product Name", font=("arial 18 bold"))
        self.name_l.place(x=0, y=70)
        self.Stock_l = Label(master, text="Enter Stocks", font=("arial 18 bold"))
        self.Stock_l.place(x=0, y=120)
        self.CP_l = Label(master, text="Enter Cost Price", font=("arial 18 bold"))
        self.CP_l.place(x=0, y=170)
        self.SP_l = Label(master, text="Enter Selling Price", font=("arial 18 bold"))
        self.SP_l.place(x=0, y=220)
        self.Vendor_l = Label(master, text="Enter Vendor Name", font=("arial 18 bold"))
        self.Vendor_l.place(x=0, y=270)
        self.Vendor_no_l = Label(master, text="Enter Vendor Phone Number", font=("arial 18 bold"))
        self.Vendor_no_l.place(x=0, y=320)

        # Entries
        self.name_e = Entry(master, width=25, font = ("arial 18 bold"))
        self.name_e.place(x=380, y=70)
        self.Stock_e = Entry(master, width=25, font = ("arial 18 bold"))
        self.Stock_e.place(x=380, y=120)
        self.CP_e = Entry(master, width=25, font = ("arial 18 bold"))
        self.CP_e.place(x=380, y=170)
        self.SP_e = Entry(master, width=25, font = ("arial 18 bold"))
        self.SP_e.place(x=380, y=220)
        self.Vendor_e = Entry(master, width=25, font = ("arial 18 bold"))
        self.Vendor_e.place(x=380, y=270)
        self.Vendor_no_e = Entry(master, width=25, font = ("arial 18 bold"))
        self.Vendor_no_e.place(x=380, y=320)

        #Button to add to database
        self.btn_add = Button(master, text='Add to database', width = 25, height=2, bg='steelblue', fg = 'white', command=self.get_items)
        self.btn_add.place(x=520, y = 370)

        #Text Box
        self.tbox = Text(master, width=60, height=18)
        self.tbox.place(x=750, y=70)
    def get_items(self,*args, **kwargs):
        #get from entries
        self.name = self.name_e.get()
        self.Stock = self.Stock_e.get()
        self.CP = self.CP_e.get()
        self.SP = self.SP_e.get()
        self.Vendor = self.Vendor_e.get()
        self.Vendor_no = self.Vendor_no_e.get()
        self.Total_CP=float(self.CP) * float(self.Stock)
        self.Total_SP=float(self.SP) * float(self.Stock)
        self.Assumed_Profits = float((self.Total_SP) - (self.Total_CP))

        #After I added this block of code i got the error
------------------------------------------------------------------------------
        if self.name=='' or self.Stock=='' or self.CP=='' or self.SP=='':
            tkinter.messagebox.showinfo('Error','Required Field(s) empty')
        else:
            sql = "INSERT INTO inventory (Name, Stock, CP, SP, Total_CP, Total_SP, Assumed_Profits, Vendor, Vendor_No. ) VALUES(?,?,?,?,?,?,?,?,?)"
            c.execute(sql, (self.name, self.Stock,self.CP, self.SP, self.Total_CP, self.Total_SP, self.Assumed_Profits, self.Vendor, self.Vendor_no))
            conn.commit()
            tkinter.messagebox.showinfo('Success','Successfully Transferred into the database')


------------------------------------------------------------------------------
root = Tk()

b = Database(root)

root.geometry('1366x768+0+0')

root.title("Add to the database")

root.mainloop()

1 个答案:

答案 0 :(得分:0)

您在Vendor_no之后有一段日子

供应商编号。

在此行:

sql =“将库存插入(名称,库存,CP,SP,Total_CP,Total_SP,Assumed_Profits,供应商,供应商编号。)VALUES(?,?,?,?,?,?,?,?,?,?)”

它不必在那里。