数据库中没有输入任何内容

2024-09-29 21:42:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个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,不包含任何内容。哪里出了问题?你知道吗


Tags: pathsrc数据库executeosdatabaseseriesdecimal

热门问题