Python Forum

Full Version: How to use place holders in tkinter sqlite
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
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.