I have to loop over all rows in the database and have to update them at some location. I have written this code:
import sqlite3
con=sqlite3.connect("Models.db")
c=con.cursor()
c1=con.cursor()
c.execute("CREATE TABLE ABC(id INTEGER PRIMARY KEY, COLVAL text)")
///inserted a few rows........
for row in c.execute("SELECT * FROM ABC"):
if $(any condition):
with con:
c1.execute("UPDATE ABC SET COLUMN1=(:COLVAL) WHERE id=(:id)",{'COLVAL':'XYZ','id':row[0]})
but I get an error:
OperationalError: database is locked
in the second query, c1.execute("UPDATE ABC SET COLUMN1=(:COLVAL) WHERE id=(:id)",{'COLVAL':'XYZ','id':row[0]})
I do not want to fetch all rows at a time and apply for a loop, as there is a lot of data. Just one row at a time which in my case:
"for row in c.execute("SELECT * FROM ABC")"
line is doing.
Does anyone know the solution for it?