P
P
pozner882021-10-20 16:52:47
Python
pozner88, 2021-10-20 16:52:47

How to make a record in the database after accessing it?

When working with the database, I encountered an error sqlite3.OperationalError: database is locked
. The error is understandable, the database is locked, so after each call I “committed” it, but still I can’t make a record in it.
Here is the code

cur.execute(f'SELECT var FROM users WHERE user_id={user.id}')
                (var,) = cur.fetchone()
                con.commit()
                cur.execute(f'SELECT cal FROM {usern} ')
                (cal,) = cur.fetchone()
                con.commit()
                # здесь математические операции с данными с предыдущих запросов
                update_data(usern, data)

Where update_data is the following function
def update_data(usern, data):
    cur.execute(f'UPDATE {usern} SET (data) = (?) ',
                    (data ))
    con.commit()

Writing to the database without previous calls to the database works fine, and when there is a SELECT before that, it says that the database is locked.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-10-20
@pozner88

cur.execute(f'SELECT cal FROM {usern} ')
(cal,) = cur.fetchone()
You selected one row and didn't close the cursor. Maybe that's the issue?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question