Sqlite update not working correctly - python

EDIT: after some test, I found out that it was not the addpoint method that failed.

I am working on a little bot-irk game. This method will update the score in the database called "score", only two players. This is sqlite database. This is basically an sql update that does not work correctly.

thank

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 that’s how I created the db score

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: unsupported type parameters

+3
source share
3 answers

Although the original author most likely moved on, I decided that I would leave here an answer to the future Googler (for example, I ^ _ ^).

I think the following error is happening here ...

ValueError: parameters are of unsupported type

... actually comes from the next line (contrary to what the author said).

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

, Cursor.execute ( ), , list, tuple 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})
+26

.

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

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

, "c" - . SQLite (.. for), . , . , :

for row in c.execute("select * from score"):
   for dummy in c.execute("select 3"):
      print row, dummy

:

  • .fetchall() : c.execute( "select * from score" ). fetchall(), , .

  • , .

  • - c.execute( "..." ) conn.cursor(). execute ( "..." ) pysqlite conn.execute( "..." ), .

, - , - .

, . , , , .

+2
source

Source: https://habr.com/ru/post/1786515/


All Articles