12 STEPS to SQLite3 in Python

Published: 21 February 2024
on channel: Life on Linux
419
12

Demoing SQLite3 in Python in under a minute


Outline:

Connect to DB (file)
Get a cursor
Create a TABLE in the DB file
Insert a single record
Save the changes with commit
Get the records
Understanding fetchall
saving fetchall into a List variable

Here are all the commands for your reference:

import sqlite3
conn = sqlite3.connect("mydb.db")
crsr = conn.cursor()
crsr.execute("""
CREATE TABLE users(
id INTEGER PRIMARY KEY AUTOINCREMENT,
user TEXT NOT NULL);
""")
crsr.execute("""
INSERT INTO users ( user ) VALUES ( "JOE" )
""")
conn.commit()
crsr.execute("SELECT * FROM users;")
crsr.fetchall()
crsr.fetchall()
crsr.execute("SELECT * FROM users;")
result = crsr.fetchall()
result


On this page of the site you can watch the video online 12 STEPS to SQLite3 in Python with a duration of hours minute second in good quality, which was uploaded by the user Life on Linux 21 February 2024, share the link with friends and acquaintances, this video has already been watched 419 times on youtube and it was liked by 12 viewers. Enjoy your viewing!