greetings, I am trying to update my sqlite3 database by selecting a specific row in the Treeview and editing it, so I can update it in the database using primary key autoincrement id
the problem: The update is not applied to the sqlite3 database it only applied to Treeview.
What I have tried:
I have tried the following:
# treeview column
def buying_checks_only_payment(self):
#unimportant treeview info's
self.buying_checkspaymenttree['columns'] = ("اdate", "اvalue", "checknum"اcheckid")
# add values into treeview
def buying_addcheck(self):
self.checksrecords=[]
self.checkid += 1
self.buying_checkspaymenttree.insert("", 'end', values=(
self.buying_check_date_var.get(), self.buying_check_value_var.get(),
self.buying_check_num_var.get(), self.checkid,self.makevar.get(),self.sellernamevar.get(),self.Buyingdate_var.get (),self.cashepayments.get(),self.buying_nocheckpic))
for child in self.buying_checkspaymenttree.get_children():
self.checksrecords.append(self.buying_checkspaymenttree.item(child)["values"])
#add treeview values into database trying to use the primry key as self.rowid
def buying_checksdb(self):
self.conn = sqlite3.connect('car dealership.db')
self.cursorObj = self.conn.cursor()
for self.checksrecords in self.checksrecords:
self.cursorObj.execute(
"INSERT INTO cars_buying_checksonly (checkdate, checkvalue, checknum, carmake, Sellername, buyingdate, entirepaymentmethod, checkpic)values(?,?,?,?,?,?,?,?)",
(self.checksrecords[0], self.checksrecords[1], self.checksrecords[2], self.checksrecords[3],
self.checksrecords[4], self.checksrecords[5], self.checksrecords[6], self.checksrecords[7]))
self.conn.commit()
self.rowid=self.cursorObj.lastrowid
print(self.rowid)
#trying to select the row and edit it in treeview to update it in the database
def buying_editcheck(self):
self.conn = sqlite3.connect('car dealership.db')
self.cursorObj = self.conn.cursor()
self.buying_selected_check_edit = self.buying_checkspaymenttree.selection()[0]
print(self.buying_checkspaymenttree.item(self.buying_selected_check_edit)['values'])
uid = self.buying_checkspaymenttree.item(self.buying_selected_check_edit)['values'][0]
self.buying_checkspaymenttree.item(self.buying_selected_check_edit, values=(
self.buying_check_date_var.get(), self.buying_check_value_var.get(),self.buying_check_num_var.get(),
self.checkid)) #is using self.rowid instead of self.checkid can help?
self.cursorObj.execute("UPDATE cars_buying_checksonly SET checkdate=?, checkvalue=?, checknum=? WHERE uid=?", (self.buying_check_date_var.get(),self.buying_check_value_var.get(),self.buying_check_num_var.get(),uid,))
self.conn.commit()