-
Notifications
You must be signed in to change notification settings - Fork 1
/
tables.py
148 lines (111 loc) · 5.04 KB
/
tables.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import sqlite3
def CreateAdminsTable(conn):
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS admins (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
email TEXT NOT NULL
)
''')
conn.commit()
def CreateStudentsTable(conn):
cursor = conn.cursor()
# add age attribute later!!
cursor.execute('''
CREATE TABLE IF NOT EXISTS students (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
email TEXT NOT NULL
)
''')
conn.commit()
def CreateSponsorsTable(conn):
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS sponsors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
email TEXT NOT NULL,
company TEXT NOT NULL
)
''')
conn.commit()
def InsertAdmin(conn, first_name: str, last_name: str, username: str, password: str, email: str):
cursor = conn.cursor()
cursor.execute('''
INSERT OR IGNORE INTO admins (first_name, last_name, username, password, email)
VALUES (?, ?, ?, ?, ?)
''', (first_name, last_name, username, password, email))
conn.commit()
def InsertStudent(conn, first_name: str, last_name: str, username: str, password: str, email: str):
cursor = conn.cursor()
cursor.execute('''
INSERT OR IGNORE INTO students (first_name, last_name, username, password, email)
VALUES (?, ?, ?, ?, ?)
''', (first_name, last_name, username, password, email))
conn.commit()
def InsertSponsor(conn, first_name: str, last_name: str, username: str, password: str, email: str, company: str):
cursor = conn.cursor()
cursor.execute('''
INSERT OR IGNORE INTO sponsors (first_name, last_name, username, password, email, company)
VALUES (?, ?, ?, ?, ?, ?)
''', (first_name, last_name, username, password, email, company))
conn.commit()
def create_student_funding_table(conn):
cursor = conn.cursor()
# change datatype of money to FLOAT!!!!
cursor.execute('''
CREATE TABLE IF NOT EXISTS applications (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id INTEGER NOT NULL,
application_name TEXT NOT NULL,
description TEXT NOT NULL,
amount_collected INTEGER NOT NULL,
amount_needed INTEGER NOT NULL,
FOREIGN KEY(student_id) REFERENCES students(id)
)
''')
conn.commit()
def InsertApplication(conn, username: str, application_name: str, description: str, amount_needed: int):
cursor = conn.cursor()
cursor.execute('''
INSERT OR REPLACE INTO applications (student_id, application_name, description, amount_collected, amount_needed)
SELECT students.id, ?, ?, ?, ?
FROM students
WHERE students.username = ?
''', (application_name, description, 0, amount_needed, username))
conn.commit()
'''UNCOMMENT THE BELOW CODE BEFORE RUNNING THE PROJECT!'''
# conn = sqlite3.connect('atiya-e-ilm.db')
# CreateAdminsTable(conn)
# CreateSponsorsTable(conn)
# CreateStudentsTable(conn)
# create_student_funding_table(conn)
# InsertAdmin(conn,'Hasan', 'Ali', 'hasan_ad', 'abc123', '[email protected]')
# InsertAdmin(conn,'Jamil', 'Akhtar', 'jamil_ad', 'abc123', '[email protected]')
# # SAMPLE INSERTIONS
# InsertStudent(conn, 'Essa','Zuberi','echu123','abc123','[email protected]')
# InsertStudent(conn, 'Laiba','Jamil','libbu123','abc123','[email protected]')
# InsertStudent(conn, 'Hania','Zuberi','hania123','abc123','[email protected]')
# InsertStudent(conn, 'Ibrahim','Haider','ibrahim123','abc123','[email protected]')
# InsertSponsor(conn, 'Abdullah','Ahmed','abdullah123','abc123','[email protected]','TCF')
# InsertSponsor(conn, 'Zain','Ali','zain123','abc123','[email protected]','ibex')
# # Update funding for Essa Zuberi
# InsertApplication(conn, 'echu123', 'Harvard Program Funds', 'I got into Harvard program. Really need the money.', 1000)
# # Update funding for Laiba Jamil
# InsertApplication(conn, 'libbu123', "UCBP Funding", "I got into UCBerkley, really need the funding. Once in a life time opportunity.", 2000)
# # Update funding for Hania Zuberi
# InsertApplication(conn, 'hania123', "Princeton program funds", "I got selected for Princeton Summer Program. I've done immense hardwork. Please help.", 1500)
# # Update funding for Ibrahim Haider
# InsertApplication(conn, 'ibrahim123', "Brown University ST Program 2023", "Got into Brown Uni's summer tech program. Please really need the funds.", 3000)
# conn.close()