Home > database >  Why do I get "sqlite3.ProgrammingError: Incorrect number of bindings supplied." even thoug
Why do I get "sqlite3.ProgrammingError: Incorrect number of bindings supplied." even thoug

Time:10-13

I'm working on a Discord bot and don't understand why I'm getting the error sqlite3.ProgrammingError: Incorrect number of bindings supplied.. The data in the database is [('123', 'hello world!'), ('111', 'testing lolz')] and when I run the command 'search' with '123' as the id the bot should reply with 'hello world!'. I've seen this post and as the answer says, I used a tuple in the Sqlite3 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()

CodePudding user response:

The sqlite3.ProgrammingError is telling something is wrong with the binding: in the statement, id="(?)" prevents from supplying.

Try this:

res = cur.execute('SELECT message FROM messages WHERE id=(?)', (id, )).fetchone()
  • Related