作者:小女人快乐方子 | 来源:互联网 | 2023-05-18 07:27
EDIT:aftersometestifoundoutthatitdontwastheaddpointmethodthatfailed.编辑:经过一些测试,我发现它
EDIT: after some test i found out that it don't was the addpoint method that failed.
编辑:经过一些测试,我发现它不是失败的addpoint方法。
I'm working on a small game to a irc bot. This method will update the score in database called 'score', the are only two players. It's a sqlite database. It's mostly the update sql that ain't working right.
我正在为一个小型游戏开发一个irc机器人。这种方法将更新数据库中的得分称为“得分”,这只是两个玩家。这是一个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
and this is the way i created the score db
这就是我创建得分db的方式
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()
error message: parameters are of unsupported type
错误消息:参数属于不受支持的类型
3 个解决方案
26
Although the original author has most likely moved on, I figured I'd leave an answer here for future Googler's (like me ^_^).
虽然原作者最有可能继续前进,但我想我会在这里为未来的Googler留下答案(就像我^ _ ^)。
I think what's happening here is that the following error...
我想这里发生的是以下错误......
ValueError: parameters are of unsupported type
ValueError:参数属于不受支持的类型
... is actually coming from the following line (contrary to what the author said).
...实际上来自以下行(与作者所说的相反)。
s = c.execute("select score from score where id=?", id)
The problem here is that Cursor.execute
accepts the query string as the first parameter (which he has right), but a list
, tuple
, or dict
as the second parameter. In this case, he needs to wrap that id
in a tuple or list, like this:
这里的问题是Cursor.execute接受查询字符串作为第一个参数(他有权),但是列表,元组或dict作为第二个参数。在这种情况下,他需要将该id包装在元组或列表中,如下所示:
s = c.execute("select score from score where id=?", (id,))
A list or tuple can be used with positional arguments (which is when you use a question mark ?
as the placeholder). You can also use a dict
and :key
for named arguments, as follows:
列表或元组可以与位置参数一起使用(当您使用问号?作为占位符时)。您还可以使用dict和:key作为命名参数,如下所示:
s = c.execute("select score from score where id=:id", {"id": id})