Home > Software engineering >  Tkinter app raises "database locked" when trying to delete record
Tkinter app raises "database locked" when trying to delete record

Time:12-12

i have a tkinter app with a login/signin page first (the signin inserts a new user to the db and works normally) and a main page with a table with elements and a button to delete an element with this function:

def delete(self):
    with sqlite3.connect(env['DB']) as conn:
        selected = self.AuthTable.Table.item(self.AuthTable.Table.selection()[0])
        curr = conn.cursor()
        curr.execute("DELETE FROM 'Authentifiants' WHERE authId=?", (selected['tags'][0],))
        conn.commit()
            
    self.AuthTable.search()

but it doesn't work and raises:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1921, in __call__    
    return self.func(*args)
  File "F:\Acces Rapide\Desktop\Tech\d3v\WorkSpace\Projects\SecurityTemp\.venv\lib\site-packages\customtkinter\windows\widgets\ctk_button.py", line 527, in _clicked
    self._command()
  File "f:\Acces Rapide\Desktop\Tech\d3v\WorkSpace\Projects\SecurityTemp\src\app\authentifiants.py", line 90, in <lambda>
    command=lambda: self.delete(),
  File "f:\Acces Rapide\Desktop\Tech\d3v\WorkSpace\Projects\SecurityTemp\src\app\authentifiants.py", line 104, in delete
    conn.commit()
sqlite3.OperationalError: database is locked

I thought it came from the fact that i don't close the conn so i changed them to with statements but same thing

here's the github project: https://github.com/jl-houss/Security

CodePudding user response:

I solved it, the problem was that the with sqlite3.connect() doesnt close the connection so the database was locked

  • Related