I am using the following code in order to insert data in 2 tables:
- Variations
- Var_entity
#begin transaction
cur.execute("begin")
id_var = 0
for red in prop_redirect["results"]["bindings"]:
var_res = red["x"]["value"].split('/')[-1]
var_type = "t1"
#insert data in table VARIATIONS
cur.execute("INSERT INTO VARIATIONS (ID, NAME, TYPE) VALUES (?, ?, ?)", (str(id_var) + "_" + str(ID), var_res, var_type))
#insert data in table VAR_ENTITY
cur.execute("INSERT INTO VAR_ENTITY(ID_ENTITY, ID_VAR, LANGUAGE) VALUES(?, ?, ?)", (str(ID), str(id_var) + "_" + str(ID), "en" ) )
id_var = id_var + 1
#commit after for loop
cur.execute("commit")
From what I understood, using "begin transaction" and "commit" allows a faster access to the database Bulk insert huge data into SQLite using Python
Are the cur.execute("begin")
and cur.execute("commit")
statements placed correctly?
Previous questions that I found on stackoverflow: