-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
45 lines (38 loc) · 1020 Bytes
/
db.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sqlite3
from sqlite3 import Error
def create_connection():
"""CREATE a database connection to a SQLite database"""
conn = None
try:
conn = sqlite3.connect("room.db")
return conn
except Error as e:
print(e)
def create_tables(conn):
"""CREATE tables"""
sql = conn.cursor()
sql.execute(
"""
CREATE TABLE IF NOT EXISTS office(
id INTEGER PRIMARY KEY AUTOINCREMENT,
number INTEGER NOT NULL,
person_id INTEGER,
start_time TEXT,
end_time TEXT,
date TEXT,
FOREIGN KEY (person_id) REFERENCES person(id)
);"""
)
sql.execute(
"""
CREATE TABLE IF NOT EXISTS person(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL,
phone INT NOT NULL
);"""
)
conn.commit()
conn.close()
if __name__ == "__main__":
create_tables(create_connection())