Answer the question
In order to leave comments, you need to log in
Why is only the first value of the table updated?
There is a code like:
for i in cursor.execute(f"PRAGMA table_info(userResource)"):
if y < 2:
y+=1
else:
cursor.execute(f"UPDATE userResource SET {i[1]} = 0 WHERE ID= {ID}")
Answer the question
In order to leave comments, you need to log in
I can't say for sure without knowing where the y variable comes from , but in the update itself the following is obtained.
First in the list of fields returned by table_info is obviously the ID field. With the first update operation, this field is reset to 0, because a construction is obtained
. Because of this, subsequent updates of other fields do not work, because there is no record with ID = your_ID anymore, you wiped it with zero.
You can add a check on the field name to prevent this from happening, like
UPDATE userResource SET ID = 0 WHERE ID = твой_ID
if i[1] != 'ID':
cursor.execute('UPDATE ...
for i in cursor.execute(f"PRAGMA table_info(userResource)").fetchall():
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question