0

I have a Players table with 3 columns id, name, wins I want to insert a row into this table. Here is my code:

import sqlite3
connection = sqlite3.connect("tournament.db")
cursor = connection.cursor()
name_insert = 'David'
wins = 10
cursor.execute("INSERT INTO Players(name,wins) VALUES (%s,%s)",(name_insert,wins))
connection.commit()
connection.close()

I got this error "sqlite3.OperationalError: near "%": syntax error". Could you help me? Thanks.

1 Answer 1

1

The SQLite Python module uses ? as the placeholder for parameters, not %s.

Check https://www.python.org/dev/peps/pep-0249/#paramstyle

Therefore, your code should work just changing the .execute call to:

cursor.execute("INSERT INTO Players(name,wins) VALUES (?, ?)",(name_insert,wins))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.