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