Connect and cursor

In-memory vs a file database.

sqlite3.connect(':memory:') lasts for one run. connect('kiosk.db') writes a file you can download and reopen.

Goal

Print rows from memory and from a file.

import sqlite3
con = sqlite3.connect(":memory:")
print(con)
con.close()
import sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("SELECT 1 + 1")
print(cur.fetchone())
con.close()
import sqlite3
con = sqlite3.connect("kiosk.db")
print(con.execute("PRAGMA database_list").fetchall())
con.close()
import sqlite3
con = sqlite3.connect(":memory:")
con.row_factory = sqlite3.Row
con.execute("CREATE TABLE t (city TEXT)")
con.execute("INSERT INTO t VALUES ('Nairobi')")
print(dict(con.execute("SELECT * FROM t").fetchone()))
con.close()