Reputation: 279
This is the database handling part of a longer Python program:
dbcon = lite.connect('spcbase.db') # Connects to database file spcbase.db.
cur=dbcon.cursor() # Creates database cursor.
cur.execute("CREATE TABLE IF NOT EXISTS spectrum(spectrumID INTEGER PRIMARY KEY AUTOINCREMENT, seriesID INTEGER, scan_ang DECIMAL, Path TEXT)")
cur.execute("CREATE TABLE IF NOT EXISTS series(seriesID INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, gpsx DECIMAL, gpsy DECIMAL, colprec DECIMAL, refangle DECIMAL)")
# Executes SQL-query that will create one table of spectrums
# and one table over series of measurements, should these
# tables or this database not exist.
with dbcon:
cur.execute("INSERT INTO series(date, gpsx, gpsy, colprec, refangle) VALUES(CURRENT_DATE, ?, ?, ?, ?)", [AP[0], AP[1], 6, refangle])
cur.execute("SELECT MAX(seriesID) FROM series")
current_series = cur.fetchone()[0]
src = u'.\\MaestroData'
dest = u'.\\target'
files=getspc(src)
i=0
for mfile in files:
oldpath=os.path.normpath(os.path.join(src,mfile))
print "oldpath: ", oldpath
newpath=os.path.normpath(os.path.join(dest,mfile))
print "newpath", newpath
os.rename(oldpath,newpath)
with dbcon:
cur.execute("INSERT INTO spectrum(seriesID, scan_ang, Path) VALUES (?, ?, ?)", [current_series, scan_dirs[i], newpath])
i=i+1
dbcon.close()
When run it gets the error "Operational error: table spectrum has no column scan_ang", despite declaring such a column only a few lines above. What is wrong?
Upvotes: 0
Views: 842
Reputation: 3419
You forgot to commit:
dbcon.commit()
Only then any modifying queries will actually take place.
Upvotes: 1