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
En esta página del sitio puede ver el video en línea 12 STEPS to SQLite3 in Python de Duración hora minuto segunda en buena calidad , que subió el usuario Life on Linux 21 febrero 2024, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 419 veces y le gustó 12 a los espectadores. Disfruta viendo!