我正在编写一个python程序,它应该将一些数据输入数据库。这不起作用。这是代码:
dbcon = lite.connect('spcbase.db') # Connects to database file spcbase.db.
print "Connected to database"
cur=dbcon.cursor() # Creates database cursor.
print "Cursor defined"
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.
cur.execute("INSERT INTO series(date, gpsx, gpsy, colprec, refangle) VALUES(CURRENT_DATE, ?, ?, ?, ?)", [AP[0], AP[1], 6, refangle])
dbcon.commit()
cur.execute("SELECT MAX(seriesID) FROM series")
dbcon.commit()
current_series = cur.fetchone()[0]
src = u'.\\MaestroData'
print src
dest = u'.\\target'
print dest
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
try:
os.rename(oldpath,newpath)
except:
print "File not moved."
cur.execute("INSERT INTO spectrum(seriesID, scan_ang, Path) VALUES (?, ?, ?)", [current_series, scan_dirs[i], newpath])
dbcon.commit()
i=i+1
(这不是整个程序,只是数据库处理部分。)运行此命令时,会创建一个名为spcbase.db的文件。它的大小为0,不包含任何内容。它出了什么问题?