0

I want to update datas from the variable, but I don't know why this error message display when I execute my code:

line 18, in save
curseur.execute("UPDATE SAV SET Commentaires_SAV=(?)", (T_Comment.get("1.0", END),) )
sqlite3.OperationalError: database is locked

I'm runing on Atom for the script, using python 3.7.2, and using SQLite3 and SQLite Studio for all datas.

import sqlite3
from tkinter import *

connexion = sqlite3.connect('Base_SAV.db')            
curseur = connexion.cursor()                       
curseur.execute("PRAGMA foreign_keys =ON")

def save(event):
   curseur.execute("UPDATE SAV SET Commentaires_SAV=(?)", (T_Comment.get("1.0", END),) )

... 

L_Comment = Label(my_frame, text='Commentaires SAV :', font=('Arial', 22, 'bold','underline')).grid(row=1, column=1, sticky='w')
T_Comment = Text(my_frame, height=10, width=100,font=('Arial',14))
T_Comment.grid(row=2, column=1,columnspan=7, sticky='w')

...
my_frame.bind("<Return>", save)

I don't know how to fix this issue. Thank you if you can help me.

Saad
  • 3,340
  • 2
  • 10
  • 32
Florian.G
  • 17
  • 8
  • do some googling: https://stackoverflow.com/questions/151026/how-do-i-unlock-a-sqlite-database – jose_bacoy Apr 23 '19 at 13:46
  • I already did it , but I didn't solve it, that's why I'm asking for my case – Florian.G Apr 23 '19 at 13:57
  • thanks for your feedback. It would only mean that the unlock is not successful. Please restart your db instance, restart your ATOM, restart your laptop. RESTART everything. – jose_bacoy Apr 23 '19 at 13:59

2 Answers2

1

It means sqlite3 journal is still running Close the database browser you are using and run the script again it will work.And also don't forget to close the connection after the end of update.

curseur.commit()
curseur.close()
AD WAN
  • 1,414
  • 2
  • 15
  • 28
  • I tried this, but nothing happened, I still have `Database is locked`. But thanks you for your help – Florian.G Apr 23 '19 at 14:26
  • the problem is why your db is locked? Are you using some isolation_level? Are you using transactions? – 1966bc Apr 23 '19 at 15:05
0

You need to connect to the database, commit the changes and then close the conexion.

Try changing this:

def save(event):
       curseur.execute("UPDATE SAV SET Commentaires_SAV=(?)", (T_Comment.get("1.0", END),) )

to this:

def save(event):
   with conexion:
      curseur.execute("UPDATE SAV SET Commentaires_SAV=(?)", (T_Comment.get("1.0", END),) )

thus avoiding the use of curseur.commit and curseur.close as the with conexion: statement stablishes the conexion and closes it by itself.