Why do I get "sqlite3.ProgrammingError: Incorrect number of bindings supplied." even though I used a tuple?
Question:
From my Discord bot I’m getting :
sqlite3.ProgrammingError: Incorrect number of bindings supplied.
The data in the database is [('123', 'hello world!'), ('111', 'testing lolz')]
and when I run ‘search’ with ‘123’ as id the bot should reply with ‘hello world!’. In this post answer says I used a tuple in the SQLite code. Here is the code for the ‘search’ command:
@tree.command(name='search', description='search for a message by id!', guild=discord.Object(id=1025197159785693284))
async def search(intr: discord.Interaction, id: str):
res = cur.execute('SELECT message FROM messages WHERE id="(?)"', (id, )).fetchone()
await intr.response.send_message(f'message {id} is: {res[0]}')
con.commit()
Answers:
Remove the double quotes in your parameter id="(?)"
, so:
res = cur.execute('SELECT message FROM messages WHERE id=(?)', (id, )).fetchone()
From my Discord bot I’m getting :
sqlite3.ProgrammingError: Incorrect number of bindings supplied.
The data in the database is [('123', 'hello world!'), ('111', 'testing lolz')]
and when I run ‘search’ with ‘123’ as id the bot should reply with ‘hello world!’. In this post answer says I used a tuple in the SQLite code. Here is the code for the ‘search’ command:
@tree.command(name='search', description='search for a message by id!', guild=discord.Object(id=1025197159785693284))
async def search(intr: discord.Interaction, id: str):
res = cur.execute('SELECT message FROM messages WHERE id="(?)"', (id, )).fetchone()
await intr.response.send_message(f'message {id} is: {res[0]}')
con.commit()
Remove the double quotes in your parameter id="(?)"
, so:
res = cur.execute('SELECT message FROM messages WHERE id=(?)', (id, )).fetchone()