i am trying to select an item from DB table using variable from optionmenu:
c.execute("SELECT category_name FROM categories")
llist = c.fetchall()
add_item_quan = Label(add_item_frame, text='الكمية ', bg='#d3e4ec', fg='#4422ee')
add_item_quan.config(font='Aerial 12 bold')
add_item_quan.grid(row=2, column=2, pady=10, padx=10)
item_cat = StringVar()
add_item_cat_list_name = OptionMenu(add_item_frame, item_cat, *llist)
add_item_cat_list_name.config(width=50, fg='white', bg='#4422ee')
add_item_cat_list_name.grid(row=4, column=1)
def add_new_item():
c.execute("SELECT id FROM categories WHERE category_name = (?)", (item_cat, ))
item_cat_id = c.fetchall()
c.execute("SELECT category_name FROM categories WHERE id = (?) ", (item_cat_id, ))
item_categ = c.fetchall()
item_name = itemsname.get()
itemsquan = int(itemsquan1)
item_quant = itemsquan
c.execute("INSERT INTO items (item_name, quan, item_category VALUES (?, ?, ?)",
(item_name, item_quant, item_categ, ))
add_item_button = Button(add_item_frame, text='مــوافــق', fg='white', bg='#4422ee', command=add_new_item)
add_item_button.grid(row=1, pady=10, padx=10)
every time it gives me the error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1541, in __call__
return self.func(*args)
File "G:/Python/warehouse/main.py", line 126, in add_new_item
c.execute("SELECT category_name FROM categories WHERE id = (?) ",
(item_cat_id, ))
InterfaceError: Error binding parameter 0 - probably unsupported type.
the data base takes text and integers as data type:
CREATE TABLE `items` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
`item_name` TEXT NOT NULL,
`quan` INTEGER NOT NULL,
`item_category` TEXT
);
Other solutions were telling to change the text types in every var to suit the DB but it didn't work, I tried it as :
def add_new_item():
c.execute("SELECT id FROM categories WHERE category_name = (?)", (str(item_cat), ))
item_cat_id = c.fetchall()
c.execute("SELECT category_name FROM categories WHERE id = (?) ", (int(item_cat_id), ))
item_categ = c.fetchall()
item_name = itemsname.get()
itemsquan = int(itemsquan1)
item_quant = itemsquan
c.execute("INSERT INTO items (item_name, quan, item_category VALUES (?, ?, ?)",
(str(item_name), int(item_quant), str(item_categ), ))
And then it gave me the same error again