C
C
ch1ps012022-03-24 20:18:34
SQLite
ch1ps01, 2022-03-24 20:18:34

Error in sqlite operation. What to do?

if gamep>0:
        cur.execute("UPDATE users SET attempts = attempts - 1 WHERE id = ?", (message.from_user.id,))
        cur.execute('SELECT attempts FROM users WHERE id = ?', (message.from_user.id,))
        gamep = cur.fetchone()[0]
        con.commit()

Provided that attempts are greater than zero, a request is sent to the database table to reduce the number of attempts, and the variable of attempts applies the value from the database, but there was a problem, by default the player has 2 attempts, everything goes fine on the first attempt, but here after the second one an error occurs:

cur.execute("UPDATE users SET attempts = attempts - 1 WHERE id = ?", (message.from_user.id,))
sqlite3.IntegrityError: UNIQUE constraint failed: users.attempts

What to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2022-03-24
@ch1ps01

It is obvious to remove the uniqueness constraint from the field of attempts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question