· 4 years ago · May 03, 2021, 02:28 PM
1from config import config
2cursor = config.cursor()
3
4class databases:
5 def create_table():
6 creating_table = """
7 CREATE TABLE IF NOT EXISTS Staff(
8 id VARCHAR(10),
9 name VARCHAR(25),
10 surname VARCHAR(25),
11 age INTEGER,
12 contact VARCHAR(12),
13 email VARCHAR(40),
14 emp_data VARCHAR(20)
15 )
16 """
17 cursor.execute(creating_table)
18 config.commit()
19
20
21 def quiring_data_from_table():
22 cursor.execute("SELECT * FROM Staff")
23 data = cursor.fetchall()
24 return data
25
26
27 def inserting_into_table(id, name, surname, age, contact, email, emp_data):
28 cursor.execute(f"INSERT INTO Staff VALUES('{id}', '{name}', '{surname}', {age}, '{contact}', '{email}', '{emp_data}')")
29 config.commit()
30
31
32 def updating_table():
33 cursor.execute("UPDATE Staff SET name ='ajnfmla' WHERE id = 'akfal'")
34 config.commit()
35
36
37 def deleting_from_table():
38 cursor.execute("DELETE FROM Staff WHERE id = 'akfal'")
39 config.commit()
40
41
42 def deleting_table():
43 cursor.execute("DROP TABLE IF EXISTS Staff")
44 config.commit()