【发布时间】:2021-09-14 21:45:57
【问题描述】:
我在 SQLite3 和 Python 3 上做错了。也许我误解了 SQLite 数据库的概念,但我希望,即使在关闭应用程序之后,数据也会存储在数据库中?当我插入数据并重新打开应用程序时,插入消失了,数据库为空。
这是我的小数据库:
import sqlite3
def createTable():
conn.execute('''CREATE TABLE VideoFile
(ID INTEGER PRIMARY KEY NULL,
FileName TEXT NOT NULL,
FilePath TEXT NOT NULL,
numOfFrames INT NOT NULL,
FPS INT NOT NULL,
Tags TEXT NOT NULL,
Voting REAL);''')
def insert():
conn.execute("INSERT INTO VideoFile (Filename, FilePath, numOfFrames,FPS, Tags, Voting) \
VALUES ('ARCAM_0010_100', 'Categories/Dirt/Small', 2340, 50, 'Bock', 1 )");
conn.execute("INSERT INTO VideoFile (Filename, FilePath, numOfFrames,FPS, Tags, Voting) \
VALUES ('ARCAM_0010_100', 'Categories/Dirt/Small', 2340, 50, 'Bock', 1 )");
def printAll(cursor):
cursor = conn.execute("SELECT ID, FileName, FilePath, numOfFrames from VideoFile")
for row in cursor:
print("ID = ", row[0])
print("FileName = ", row[1])
print("FilePath = ", row[2])
print("numOfFrames = ", row[3], "\n")
print("Operation done successfully")
conn.close()
conn = sqlite3.connect('AssetBrowser.db')
createTable()
#comment out after executing once
insert()
printAll()
我哪里做错了?
【问题讨论】: