S
S
Slanty2020-03-15 10:31:06
Python
Slanty, 2020-03-15 10:31:06

How to get rid of the "Database is locked" error?

I have a telegram bot script.
When a person reaches the purchase stage, the bot crashes with the "Database is locked" error.
The bot crashes on the last line (connection.commit()).

connection = sqlite3.connect('database.sqlite')
      q = connection.cursor()
      bot.delete_message(chat_id=call.message.chat.id,message_id=call.message.message_id)
      q.execute("SELECT name FROM tovar where id = "+ str(call.data[4:]))
      aaaaa = q.fetchone()
      if aaaaa != None:
        q.execute("SELECT balans FROM ugc_users where id = "+ str(call.from_user.id))
        bal_us = q.fetchone()
        q.execute("SELECT price FROM tovar where id = "+ str(call.data[4:]))
        price_tovar = q.fetchone()
        if int(bal_us[0]) >= int(price_tovar[0]):
          q.execute("update ugc_users set balans = balans - " + str(price_tovar[0])+" where id = " +str(call.from_user.id))
          connection.commit()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question