-
Notifications
You must be signed in to change notification settings - Fork 1
/
database_connection.py
65 lines (47 loc) · 1.69 KB
/
database_connection.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
import sqlite3
db = sqlite3.connect("db",check_same_thread = False)
connection = None
try:
connection = db.cursor()
print('Connection established')
except Exception as e:
print('Connection Failed')
def create_user():
connection.execute('''CREATE TABLE IF NOT EXISTS Data(
FirstName text NOT NULL,
LastName text,
emailaddress varchar NOT NULL UNIQUE,
Username varchar NOT NULL UNIQUE,
password varchar NOT NULL
)''')
db.commit()
def add_user_data(first_name, last_name, emailaddress, user, password):
connection.execute(
'''INSERT INTO Data(FirstName,LastName,emailaddress,Username,password) values (?,?,?,?,?);''',
(first_name, last_name, emailaddress, user, password))
db.commit()
def display_data():
connection.execute('''SELECT * FROM Data''')
rows = connection.fetchall()
return rows
def delete_data():
connection.execute('''delete from Data''')
print('Deleted Successfully')
db.commit()
def column_data(column_name=None):
if column_name == 'emailaddress':
connection.execute('''select emailaddress from Data''')
col = connection.fetchall()
return col
elif column_name == 'username':
connection.execute('''select Username from Data''')
col = connection.fetchall()
return col
else:
connection.execute('''select * from Data''')
rows = connection.fetchall()
return rows
def two_columns_retrieval(user, passe):
connection.execute('''select * from Data where Username=? and password=?''', (user, passe))
rows = connection.fetchall()
return rows