Answer the question
In order to leave comments, you need to log in
Python and SQLite 3. Why can't insert data?
Execution does not cause errors, but there is no data in the database.
import sqlite3
db = sqlite3.connect('database.db')
cursor = db.cursor()
cursor.execute("DROP TABLE IF EXISTS video")
sql = """
CREATE TABLE video(
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
file VARCHAR(255), title VARCHAR(255))
"""
cursor.execute(sql)
data = [{'filename': '1.mp4', 'title': 'MegaTitle'}, {'filename': '2.mp4', 'title': 'MegaTitle2'},]
for video in data:
cursor.execute("INSERT INTO video(file, title) VALUES(:filename, :title)", video)
cursor.close()
db.close()
Answer the question
In order to leave comments, you need to log in
It's decided. You need to commit the changes before closing the connection.
db.commit()
db.close()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question