I have the following script to fill a test database for me.
#!/usr/bin/python
import random, sys, sqlite3
con = sqlite3.connect('test.db')
cur = con.cursor()
cur.execute("DROP TABLE IF EXISTS EXAMPLE")
cur.execute("CREATE TABLE EXAMPLE(FIRST TEXT, SECOND TEXT)")
for i in range(0, 99999999):
one = format(i, '08d')
two = "%0.8d" % random.randint(0,99999999)
cur.execute("INSERT INTO EXAMPLE VALUES(\'"+one+"\',\'"+two+"\')")
con.commit()
# to have some feedback of the progress
if i % 100000 == 0:
print (str(i))
con.close()
print ("done")
# wait in the script..
sys.stdin.readline()
Now the script takes up all the RAM it can (runs currently in a VM with 3GB - takes up ~2.8GB) within about 2 minutes (edit: within a few seconds) and never reached the if i % 100000 == 0:
.
If I terminate it and check the test.db
file it's 3KB big and contains the table only, no entries.
Do I need to close and re-open the connection every now and then?