Python Forum
How to use place holders in tkinter sqlite - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: How to use place holders in tkinter sqlite (/thread-26745.html)



How to use place holders in tkinter sqlite - scratchmyhead - May-12-2020

I have a program with a sqlite database and I'm trying to update a record by using place holders. I'm not sure why but I'm getting the following error: TypeError: function takes at most 2 arguments (3 given) So here is a sample of my code if anyone can figure out what I'm doing wrong.


conn = sqlite3.connect('roominventory.db')
        c = conn.cursor()
        c.execute("SELECT * FROM rooms")
        records = c.fetchall()

        for record in records:
            if record[0] == roomget:
                break

        t = ("N",)
        rm = (roomget,)
        c.execute("UPDATE rooms SET vacant = ? WHERE number = ?", t, rm)

        c.fetchall()
        conn.commit()
        conn.close()

I found out the correct code to use. The correct way is the following:

conn = sqlite3.connect('roominventory.db')
        c = conn.cursor()
        c.execute("SELECT * FROM rooms")
        records = c.fetchall()

        for record in records:
            if record[0] == roomget:
                break

        t = "N"
        rm = roomget
        c.execute("UPDATE rooms SET vacant = ? WHERE number = ?", (t, rm))

        c.fetchall()
        conn.commit()
        conn.close()



RE: How to use place holders in tkinter sqlite - Larz60+ - May-12-2020

Quote: I'm getting the following error: TypeError
Please Post entire unmodified error traceback (in bbcode error tags)
It contains information that is most helpful in finding cause or error.