-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data_Base.py
41 lines (29 loc) · 917 Bytes
/
Data_Base.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
import sqlite3
def get_connection():
con = sqlite3.connect('filename')
print('DataBase opened')
def create_table(con):
con.execute('''CREATE TABLE IF NOT EXISTS leaf_db(
NAME TEXT NOT NULL,
USERNAME TEXT NOT NULL,
EMAIL TEXT NOT NULL,
PASSWORD TEXT NOT NULL)''')
print('Table created')
con.close()
def insert_records(con, obj):
data = " INSERT INTO leaf_db(NAME, USERNAME, EMAIL, PASSWORD) VALUES (?,?,?,?)"
con.execute(data, (obj.name, obj.username, obj.email, obj.password))
con.commit()
print('Record inserted')
def update_records(con, obj):
qr = "UPDATE leaf_db set NAME = ? where EMAIL= ? "
con.execute(qr,(obj.name, obj.email))
con.commit()
print('Updated')
def fetch_records(con):
qr = "SELECT * FROM leaf_db"
data = con.execute(qr)
print(data)
def close_connection():
con.close()
print('DataBase closed')