我试图更新数据库表,但我不断收到此错误:
“ recovermathstestresults”屏幕中的文件“ /Users/tom/Documents/Documentation/Code/currentcode.py”,第554行 [(avgpercentagescore),(testofcompletes),(improveon),(studentusername),(mathstopic),(date)]) TypeError:函数正好接受1个参数(给定2个参数)
cursor.executescript('''UPDATE mathstopics
SET avgpercentagescore = ?, numberoftestscompleted = ?, improveon = ?
WHERE studentusername = ? AND mathstopic = ? AND date = ?;) VALUES(?,?,?,?,?,?)''',
[(avgpercentagescore), (numberoftestscompleted), (improveon), (studentusername), (mathstopic), (date)])
db.commit()
我在这里做错了什么?我可能做错了什么?
所有帮助将不胜感激。我不能弄清楚这个问题:(
答案 0 :(得分:-1)
您的executescript
希望执行一个字符串查询,但是您要提供2个参数查询和变量。
我建议您使用变量创建一个字符串,然后使用db.commit
示例:
cursor.executescript('''UPDATE mathstopics
SET avgpercentagescore = {0}, numberoftestscompleted = {1}, improveon = {2}
WHERE studentusername = {3} AND mathstopic = {4} AND date = {5};'''.format(avgpercentagescore,numberoftestscompleted, improveon,studentusername,mathstopic, date))
db.commit()