I am new to Python.
def checkstock(self):
con = sqlite3.connect(database=r'ims.db')
cur = con.cursor()
cur.execute("PRAGMA read_uncommitted = true;")
try:
cur.execute("Select occode from ordercart")
occode = cur.fetchall()
for elem in occode:
for y in range (20):
for x in range(1,8):
cur.execute(f"Select occolor{x} from ordercart where occode=? limit 1 offset {int(y)}", elem)
occolor = cur.fetchone()
cur.execute(f"Select ocxs{x} from ordercart where occode=? limit 1 offset {int(y)}", elem)
ocxs = cur.fetchone()
cur.execute(f"Select nixs{x} from newitem where nicode=? limit 1 offset {int(y)}", elem)
nixs = cur.fetchone()
for ordercartxs in ocxs or ():
for newitemxs in nixs or ():
a = int(nixs[0]) - int(ocxs[0])
if a < 0 :
messagebox.showerror("Error", f"Stock {elem} {occolor} Size XS :{a}", parent = self.root)
else:
print(a)
cur.execute(f"Update newitem set nixs{x}=? where nicode=?",(a, elem[0],))
con.commit()
messagebox.showinfo("Successful","IV and DO created successfully")
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}", parent = self.root)
This is the code. But it always shows "database is locked" and the output failed. I realize that there is a ims.db-journal file keep showing up whenever I run the program. Is there any solution for this? Tqsm!