Hi.
I have a problem that I am tearing my hair out to solve. I am trying to transfer tens of thousands of records into a sqlite db using the script below.
The script seems to run okay and I can see the db growing as it runs to some 19megs but when I try and view the database it is empty and subsequently reports a size of 2kb!
See my rough code below. I am a journalist and not a pro programmer so be gentle.:)
Some of the things I have in there like isolation_level and BEGIN TRANSACTION and check_same_thred solved another problem I was having with the script throwing a "can't open database error' earlier. I don't have clue what they do but they solved that problem - and no doubt caused this one.
Is sqlite maybe the wrong option for a database like this. I'm trying to avoid mysql so I don't have to hassle with servers etc.
import os
import sqlite3
from xlrd import open_workbook
#----------------------------------------
# get data from excel file
#----------------------------------------
os.chdir(u'C://Users//andrew.trench//Desktop//Trust records//Pmb//')
list_of_files=os.listdir(u'C://Users//andrew.trench//Desktop//Trust records//Pmb')
# create SQL table and fill it with data
#----------------------------------------
os.chdir(u'C://Python26//')
database = sqlite3.connect('trusts.db',timeout=10, isolation_level=None, check_same_thread = False)
cursor = database.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS pretoria (
RecordNr INTEGER,
FileNo TEXT,
TrustName TEXT,
AuthorizationDate TEXT,
Auditor TEXT,
TrusteeSurname TEXT,
TrusteeFirstName TEXT,
TrusteeCompany TEXT,
TrusteeTelephoneWork TEXT)''')
cursor.execute('BEGIN TRANSACTION')
for filename in list_of_files:
print filename
book=open_workbook(u'C://Users//andrew.trench//Desktop//Trust records//Pmb//'+filename)
sheet=book.sheet_by_index(0)
counter=1
for rownum in range(sheet.nrows):
while counter < sheet.nrows:
database = sqlite3.connect('trusts.db',timeout=10, isolation_level=None, check_same_thread = False)
cursor.execute("PRAGMA page_size = 32768;")
database.commit()
data=sheet.row_values(counter)
while len(data)>9:
data.pop((len(data)-1))
cursor.execute('INSERT INTO pretoria VALUES (?,?,?,?,?,?,?,?,?)', data)
database.commit()
counter=counter+1
database.close()