为什么即使我使用了元组,我也会得到"sqlite3.ProgrammingError: Incorrect number of bindings supplied."?



从我的Discord机器人中我得到了:

sqlite3.ProgrammingError:提供的绑定数不正确。

数据库中的数据是[('123', 'hello world!'), ('111', 'testing lolz')],当我以"123"作为id运行"search"时,机器人程序应该回复"hello world!"。在这篇文章中,回答说我在SQLite代码中使用了一个元组。以下是"搜索"命令的代码:

@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()

删除参数id="(?)"中的双引号,因此:

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

最新更新