runtime

database lab program SQLite from Python · changes are saved

Database Lab

Query and change a real database from Python, with sqlite3, transactions and indexes. Reset puts the data back.

Pick another database to see different activities.

Start here: read rows from a table

Open a table under "tables in" below and press Show rows to see its data. Run the SELECT in the SQL tab, then do the same from Python: connect, run the query, fetch the rows and print them.

what you'll try
Run the Python code, then the SQL version in the SQL tab. Change it and run it again: the database keeps your changes.
what you should see
The column names, then the first five rows of the table, one tuple per row, then how many rows it has. Python's sqlite3 runs the same SELECT you'd type in the SQL tab: connect() opens the file, execute() runs the query, fetchall() hands you the rows.

tables in store.db

…

how the lab works

Online Store is loaded into store.db, a SQLite file kept in this browser. Python opens it with sqlite3.connect("store.db"); the SQL tab runs on the same file. Whatever you commit stays until you reset it.

first-query.py

Reset store.db?

Every change you made to store.db is undone: it's rebuilt from the original Online Store data. Your code is kept.

Python Database Lab · Runtime