编辑:经过一些测试,我发现它不是失败的添加点方法。
我正在为 irc 机器人开发一个小游戏。此方法将更新名为“score”的数据库中的分数,只有两名玩家。这是一个sqlite数据库。主要是更新sql 无法正常工作。
Thanks
def addpointo(phenny, id, msg, dude):
try:
for row in c.execute("select score from score where id = '0'"):
for bow in c.execute("select score from score where id = '1'"):
if int(row[0]) == 3:
phenny.say("Winner is " + dude)
clear("score") # clear db
clear("sap") # clear db
elif int(bow[0]) == 3:
phenny.say("Winner is " + dude)
clear("score") # clear db
clear("sap") # clear db
else:
phenny.say(msg)
s = c.execute("select score from score where id=?", id)
a = int(s.fetchone()[0]) + 1
print a
c.execute("update score SET score =? where id =?", (a, id)) #here i got some prolem
conn.commit()
except Exception:
phenny.say("Error in score. Try to run '.sap clear-score' and/or '.sap clear-sap'")
pass
这就是我创建分数数据库的方式
def createscore():
if not (checkdb("score") is True):
c.execute('''create table score (id int, score int)''')
c.execute('insert into score values (0, 0)')
conn.commit()
c.execute('insert into score values (1, 0)')
conn.commit()
错误消息:参数的类型不受支持
虽然原作者很可能已经离开了,但我想我应该在这里为未来的 Google 员工(像我一样^_^)留下一个答案。
我认为这里发生的是以下错误......
ValueError: parameters are of unsupported type
...实际上来自以下行(与作者所说的相反)。
s = c.execute("select score from score where id=?", id)
这里的问题是Cursor.execute
接受查询字符串作为第一个参数(他有权利),but a list
, tuple
, or dict
作为第二个参数。在这种情况下,他需要将其包装起来id
在元组或列表中,如下所示:
s = c.execute("select score from score where id=?", (id,))
列表或元组可以与位置参数一起使用(即当您使用问号时?
作为占位符)。您还可以使用dict
and :key
对于命名参数,如下所示:
s = c.execute("select score from score where id=:id", {"id": id})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)