I'm Trying to delete an item in SQLite Database from a tree view in TKinter GUI. The tree view returns a value like I002. Tried to convert to string or in a variable also, nothing works. Here is the delete function code
def Database():
global conn, cursor
conn = sqlite3.connect('pythontut.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS `anno` (mem_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, daytype TEXT, time TEXT, audiofile TEXT)")
def Create():
TIME = CHOUR.get() +":"+ CMIN.get() + ":"+ CSEC.get() + " "+CPERIOD.get()
print(TIME)
if DAYTYPE.get() == "" or TIME == "":
txt_result.config(text="Please complete the required field!", fg="red")
else:
Database()
cursor.execute("INSERT INTO `anno` (daytype, time, audiofile) VALUES(?, ?, ?)", (str(DAYTYPE.get()), str(TIME), str(AUDIO_SELECTION.get())) )
conn.commit()
DAYTYPE.set("")
cursor.close()
conn.close()
txt_result.config(text="Created a data!", fg="green")
def Read():
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM `anno` ORDER BY `daytype` ASC")
fetch = cursor.fetchall()
for data in fetch:
tree.insert('', 'end', values=(data[0], data[1], data[2], data[3]))
cursor.close()
conn.close()
txt_result.config(text="Successfully read the data from database", fg="black")
def Delete():
selected_items = tree.selection()
Database()
for selected_item in selected_items:
tree.delete(selected_item)
print(str(selected_item))
cur = conn.cursor()
cur.execute("DELETE FROM anno WHERE mem_id = ?", (selected_items,))
conn.commit()
conn.close()
Returning this following error
cur.execute(sql)
sqlite3.OperationalError: no such column: I002
I'm trying to Delete the selected items from the treeview in the TKinter as well as in the SQLite Database.