1 | n/a | # Not referenced from the documentation, but builds the database file the other |
---|
2 | n/a | # code snippets expect. |
---|
3 | n/a | |
---|
4 | n/a | import sqlite3 |
---|
5 | n/a | import os |
---|
6 | n/a | |
---|
7 | n/a | DB_FILE = "mydb" |
---|
8 | n/a | |
---|
9 | n/a | if os.path.exists(DB_FILE): |
---|
10 | n/a | os.remove(DB_FILE) |
---|
11 | n/a | |
---|
12 | n/a | con = sqlite3.connect(DB_FILE) |
---|
13 | n/a | cur = con.cursor() |
---|
14 | n/a | cur.execute(""" |
---|
15 | n/a | create table people |
---|
16 | n/a | ( |
---|
17 | n/a | name_last varchar(20), |
---|
18 | n/a | age integer |
---|
19 | n/a | ) |
---|
20 | n/a | """) |
---|
21 | n/a | |
---|
22 | n/a | cur.execute("insert into people (name_last, age) values ('Yeltsin', 72)") |
---|
23 | n/a | cur.execute("insert into people (name_last, age) values ('Putin', 51)") |
---|
24 | n/a | |
---|
25 | n/a | con.commit() |
---|
26 | n/a | |
---|
27 | n/a | cur.close() |
---|
28 | n/a | con.close() |
---|