pythonsqlitetkintertext-widget

Can't get text input from Tkinter Text widget into sqlite3 database


trying to get text input from a tkinter Text widget with variable name sponsor with the following command

conn = sqlite3.connect(tables.db)

cursor = conn.cursor()

cursor.execute("CREATE TABLE IF NOT EXISTS `sponsors` (sponsor_id  INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, sponsor TEXT)")
cursor.execute("INSERT INTO 'sponsors' (sponsor) VALUES(?)", sponsor.get('1.0', 'end'))

conn.commit()

I typed in "Vector Linkz Limited" to be inserted into the sponsors table in the sqlite Database but gut the following error

cursor.execute("INSERT INTO 'sponsors' (sponsor) VALUES(?)", sponsor.get('1.0', 'end')) sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 21 supplied.

I don't even know what this means to be honest, can anyone help me out please. Thanks.


Solution

  • The second argument of cursor.execute(...) is expected to be a tuple or list, so change

    cursor.execute("INSERT INTO 'sponsors' (sponsor) VALUES(?)", sponsor.get('1.0', 'end'))
    

    to

    cursor.execute("INSERT INTO 'sponsors' (sponsor) VALUES(?)", [sponsor.get('1.0', 'end')])