加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Sqlite更新无法正常工作 – python

发布时间:2020-12-12 18:53:08 所属栏目:百科 来源:网络整理
导读:编辑:经过一些测试,我发现它不是失败的addpoint方法. 我正在为一个小型游戏开发一个irc机器人.这种方法将更新数据库中的得分称为“得分”,这只是两个玩家.这是一个sqlite数据库.它主要是更新sql无法正常工作. 谢谢 def addpointo(phenny,id,msg,dude): try:
编辑:经过一些测试,我发现它不是失败的addpoint方法.

我正在为一个小型游戏开发一个irc机器人.这种方法将更新数据库中的得分称为“得分”,这只是两个玩家.这是一个sqlite数据库.它主要是更新sql无法正常工作.

谢谢

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

这就是我创建得分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()

错误消息:参数属于不受支持的类型

解决方法

虽然原作者很可能继续前进,但我想我会在这里为未来的Googler留下答案(就像我^ _ ^).

我想这里发生的是以下错误……

ValueError:参数属于不受支持的类型

……实际上来自以下几行(与作者所说的相反).

s = c.execute("select score from score where id=?",id)

这里的问题是Cursor.execute接受查询字符串作为第一个参数(他有权),但是列表,元组或dict作为第二个参数.在这种情况下,他需要将该id包装在元组或列表中,如下所示:

s = c.execute("select score from score where id=?",(id,))

列表或元组可以与位置参数一起使用(当您使用问号?作为占位符时).您还可以使用dict和:key作为命名参数,如下所示:

s = c.execute("select score from score where id=:id",{"id": id})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读