获取错误“sqlite3.OperationalError:near”)“:语法错误”

2024-09-27 07:18:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从GUI向数据库添加数据,并使用SQLite,结果出现了这个错误

Tkinter回调中的异常 回溯(最近一次呼叫最后一次): 文件“C:\Users\max\AppData\Local\Programs\Python37\lib\tkinter\uuu init\uuuu.py”,第1705行,在调用中 返回self.func(*args) 文件“C:\Users\max\Documents\compsci stuff\NEW compsci.py”,第196行,在get\U项目中 C.execute(sql,vari) sqlite3.error:near“:语法错误

  def get_items(self,*args,**kwargs): #this function gets the items from the entry boxes

        self.carmake= self.carmake_e.get()

        self.carmodel= self.carmodel_e.get()

        self.regi= self.regi_e.get()

        self.colour= self.colour_e.get()

        self.cost= self.cost_e.get()

        self. tcost= self. tcost_e.get()

        self.sellprice= self.sellprice_e.get()

        self.assumedprofit= self.assumedprofit_e.get()

        if self.carmake == " or self.carmodel" == "== self.colour == ":
            print ("WRONG")
            TKInter.messagebox.showinfo("error", "please enter values for car make, model and colour")
        else:
            print ("solid m8")
            sql= "INSERT INTO inventory(car_make,car_model, registration_plate,colour,cost,total_cost,selling_price,assumed_profit) VALUES) (?,?,?,2,?,?,2,?)"
            vari=(self.carmake, self.carmodel,self.regi,self.colour,self.cost,self.tcost,self.sellprice,self.assumedprofit)
            C.execute(sql ,vari)
            C.execute(sql(self.name,self.carmake, self.carmodel, self.regi,self.colour, self.cost,self.tcost,self.sellprice,self.assumedprofit))
            conn.commit()
            tkinter.messagebox.showinfo("success", "succesfully added to databse!")

Tags: 文件selfexecutesqlgetcarcostcolour

热门问题