SQLite3 및 Python 3으로 잘못하고 있습니다. 어쩌면 내가 SQLite 데이터베이스의 개념을 오해했을 수도 있지만 응용 프로그램을 닫은 후에도 데이터가 데이터베이스에 저장된다고 생각합니까? 데이터를 삽입하고 응용 프로그램을 다시 열면 삽입이 사라지고 데이터베이스가 비어 있습니다.Python Sqlite3 - 데이터가 영구적으로 저장되지 않습니다.
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()
어디 내가 뭐하는 거지 잘못된 : 여기
내 작은 DB입니까?
O_o 매우 빨랐습니다! 대답과 링크에 감사드립니다! – user1767754