0

Can't insert variable to sqlite db

def new_player(nickname):
    conn = sqlite3.connect('db/pythonsqlite.db')
    c = conn.cursor()
    c.execute("INSERT  INTO Players VALUES (NULL, ?)", (nickname))
    conn.commit()
    conn.close()
new_player(nickname)

I get this error:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 7 supplied.

7 is the number of letters in nickname string

2

1 Answer 1

3

it should be

c.execute("INSERT  INTO Players VALUES (NULL, ?)", (nickname,))

this way you supply one-element tuple. Note the comma.

Sign up to request clarification or add additional context in comments.

1 Comment

Bonus +1 for making the binding value a one-element tuple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.