I am doing something wrong with SQLite3 and Python 3. Maybe i misunderstood the concept of SQLite Databases, but i expect, that data is stored in the database even after closing the application? When i insert Data and reopen the application, the inserts are gone, database is empty.
Here is my Little DB:
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], "
")
print("Operation done successfully")
conn.close()
conn = sqlite3.connect('AssetBrowser.db')
createTable()
#comment out after executing once
insert()
printAll()
Where i am doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…