小编B.T*_*ris的帖子

Python 3 sqlite 参数化 SQL 查询

我一直在尝试使用 Python 3 和 sqlite 模块进行参数化 SQL 查询,并且仅使用一个变量就成功了。但是,当使用两个变量时,出现IndexError: tuple index out of range错误。关于导致此错误的原因有什么建议吗?

sql = ("select exists(SELECT * from USERS where PASSWORD = '{0}' AND USERNAME = '{1}')")
args = (var1,var2)
cursor = database_connection.execute((sql).format(args))
Run Code Online (Sandbox Code Playgroud)

python sqlite python-3.x

3
推荐指数
1
解决办法
4909
查看次数

标签 统计

python ×1

python-3.x ×1

sqlite ×1