-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite.py
28 lines (26 loc) · 822 Bytes
/
sqlite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sqlite3
conn = sqlite3.connect("people.db")
columns = [
"id INTEGER PRIMARY KEY",
"lname VARCHAR UNIQUE",
"fname VARCHAR",
"timestamp DATETIME",
]
create_table_cmd = f"CREATE TABLE person ({','.join(columns)})"
conn.execute(create_table_cmd)
# -----------------------------------------------------------------
people = [
"1, 'Fairy', 'Tooth', '2022-10-08 09:15:10'",
"2, 'Ruprecht', 'Knecht', '2022-10-08 09:15:13'",
"3, 'Bunny', 'Easter', '2022-10-08 09:15:27'",
]
for person_data in people:
insert_cmd = f"INSERT INTO person VALUES ({person_data})"
conn.execute(insert_cmd)
conn.commit()
# -----------------------------------------------------------------
cur = conn.cursor()
cur.execute("SELECT * FROM person")
people = cur.fetchall()
for person in people:
print(person)