1

When I run a routine to open my database and insert values i get the error: sqlite3.OperationalError: database is locked

and a file is created with my database name (in the same directory) system.db-journal.

Could anyone please help me? Before i run this routine i ran a login routine which accessed the database successfully with no errors. I have many other routines in the backend file what access the database and they finish with conn.commit and conn.close thus I don't know what the issue is - but feel it has something to do with the file generated.

A small subsection of the function which induces the error (Willing to provide more code but will get complicated quickly)

#frontend.py                                                        
backend.Database.customerOrders(choice,size,milkOptions,today,                                           
PageTwo.quantity,PageTwo.price,customerID)

#Backend.py
#INSERT ORDER DETAILS
def customerOrders(product,size,milkOptions,date,quantity,price,customerID):
    conn=sqlite3.connect("system.db")
    cur=conn.cursor()
    cur.execute("INSERT INTO customerOrders VALUES (NULL,?,?,?,?,?,?,?)",(product,size,milkOptions,date,quantity,price,customerID))
    conn.commit()
    conn.close()

sqlite3.OperationalError: database is locked

File created in same directory system.db-journal.

Dan
  • 23
  • 1
  • 7
  • Do you have multiple open connections? See https://stackoverflow.com/questions/3172929/operationalerror-database-is-locked – Max Candocia Aug 18 '19 at 15:34
  • I have conn.close() after every type of query, but I find it odd how a file is created about the database upon one of my queries, and this has something to do with the issue? – Dan Aug 18 '19 at 16:07
  • The issue could be if you are running multiple programs/processes that used backend.py. If you are running a server it is possible that it is using multiple processes, but I can't tell from the information given. – Max Candocia Aug 18 '19 at 16:38

0 Answers0