Python Forum
[Tkinter] sqlite3 update statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] sqlite3 update statement
#1
Hi,

I am trying to update 2 columns, one of which will take its value from a label "thetoken".

def assign_exam():
    global thefullname
    global assign_exams
    global names
    global namechoosen
    global examchoosen
    global my_label
    global thetoken

    assign_exams = Toplevel(screen)
    assign_exams.geometry("500x550")
    assign_exams.title("Exam Assignments")

    app_width = 400
    app_height = 350
    screen_width = screen.winfo_screenwidth()
    screen_height = screen.winfo_screenheight()
    x = (screen_width / 2) - (app_width / 2)
    y = (screen_height / 2) - (app_height / 2)
    assign_exams.geometry(f'{app_width}x{app_height}+{int(x)}+{int(y)}')

    names = StringVar()
    exams = StringVar()

    Label(assign_exams, text="Please make your choices to assign an exam token:\n").grid(row=0, column=0)
    Label(assign_exams, text="Choose a name:\n").grid(row=1, column=0, sticky=W)
    namechoosen = ttk.Combobox(assign_exams, textvariable=names)
    namechoosen['values'] = combo_input()
    namechoosen.grid(row=2, column=0, sticky=E)
    namechoosen.current(0)
    my_btn = Button(assign_exams, text="Update Exam List", command = combo_input2)
    my_btn.grid(row=2, column=1, sticky=E)
    Label(assign_exams, text="Choose an exam:\n").grid(row=3, column=0, sticky=W)
    examchoosen = ttk.Combobox(assign_exams, textvariable=exams)
    examchoosen['values'] = ""
    examchoosen.grid(row=4, column=0, sticky=E)
    Label(assign_exams, text="").grid(row=5, column=0, sticky=W)
    thetoken = Label(assign_exams, font=("Ariel",20),text="Token#:"+str(randint(7000000,9999999)))
    thetoken.grid(row=6, column=0, sticky=W)
    Label(assign_exams, text="").grid(row=7, column=0, sticky=W)
    Button(assign_exams, text="Assign Exam", command = confirm_assignment).grid(row=8, column=0)
    Button(assign_exams, text="Cancel", command=assign_exams.destroy).grid(row=8, column=1)

def confirm_assignment():
    conn = sqlite3.connect('emsat_data.db')
    c3 = conn.cursor()
    c3.execute("UPDATE exam_requests SET exam_enabled ='yes', exam_token =? where name =? and exam_type=? and exam_enabled='no'",
               (thetoken.cget("text"), namechoosen, examchoosen))
    conn.commit()
    conn.close()

def combo_input():
    conn2 = sqlite3.connect('emsat_data.db')
    c2 = conn2.cursor()
    c2.execute("SELECT DISTINCT name from exam_requests")
    conn2.commit()
    data = []

    for row in c2.fetchall():
        data.append(row[0])
    return data

def combo_input2():
    global namechoosen

    conn2 = sqlite3.connect('emsat_data.db')
    c2 = conn2.cursor()
    c2.execute("SELECT * from exam_requests where name=?", (namechoosen.get(),))
    conn2.commit()
    data = []

    for row in c2.fetchall():
        data.append(row[1])
    examchoosen['values'] = data
I am getting this error:
Error:
File "C:\Users\ramit\PycharmProjects\Emsat\main.py", line 423, in confirm_assignment c3.execute( sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.
line 423 is the update statement.
Thanks.
Reply
#2
Please always show entire unaltered error traceback as it contains valuable information on program flow.
Does this query run from sqlite3 command line interpreter?
(type sqlite3 from command line) of course with variable names replaced with values.
Also, the second comma may be an issue
# Try changing this
c2.execute("SELECT * from exam_requests where name=?", (namechoosen.get(),))
#  to this
c2.execute("SELECT * from exam_requests where name=?", (namechoosen.get()))
rwahdan likes this post
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020