forked from xiaomi388/comsw-4156-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
userTableDDL.py
78 lines (65 loc) · 1.78 KB
/
userTableDDL.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sqlite3
from sqlite3 import Error
def init_db():
# creates User Table
conn = None
try:
conn = sqlite3.connect('sqlite_db')
conn.execute("CREATE TABLE IF NOT EXISTS User ("
"email text PRIMARY KEY,"
"password text NOT NULL,"
"name text,"
"zipcode integer,"
"rating integer,"
"transaction_count integer,"
"phone_number integer) ;")
print('User Table created')
except Error as e:
print(e)
finally:
if conn:
conn.close()
def insert_mock_user():
try:
mock_user = ("[email protected]", "passwd",
"Zhihao Jiang", "10025", "10", "1", "6466466646")
conn = sqlite3.connect("sqlite_db")
conn.execute(
"INSERT INTO User "
"(email, password, name, zipcode,"
" rating, transaction_count, phone_number) "
"VALUES (?, ?, ?, ?, ?, ?, ?)", mock_user
)
conn.commit()
print(f"mock user inserted {mock_user}")
except Error as e:
print(e)
return
def check_User_Table():
try:
conn = sqlite3.connect("sqlite_db")
users = conn.execute(
"Select * from User "
)
conn.commit()
print("user table has ")
for user in users:
print(user)
except Error as e:
print(e)
return
def clear():
conn = None
try:
conn = sqlite3.connect('sqlite_db')
conn.execute("DROP TABLE User")
print('Table User cleared')
except Error as e:
print(e)
finally:
if conn:
conn.close()
clear()
init_db()
insert_mock_user()
check_User_Table()