-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwith_query.py
More file actions
35 lines (27 loc) · 1.07 KB
/
Copy pathwith_query.py
File metadata and controls
35 lines (27 loc) · 1.07 KB
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
import sqlite3
def create_table():
conn = sqlite3.connect('myclass.db')
conn.execute('''CREATE TABLE IF NOT EXISTS students
(id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
roll_number INTEGER NOT NULL,
address TEXT NOT NULL);''')
conn.close()
def add_student(first_name, last_name, roll_number, address):
conn = sqlite3.connect('myclass.db')
conn.execute('''INSERT INTO students (first_name, last_name, roll_number, address)
VALUES (?, ?, ?, ?);''', (first_name, last_name, roll_number, address))
conn.commit()
conn.close()
def display_students():
conn = sqlite3.connect('myclass.db')
students = conn.execute("SELECT * FROM students;").fetchall()
for student in students:
print(student)
conn.close()
create_table()
add_student("Om", "Kadam", 37, "Goregaon")
add_student("Manav", "Ghadi", 29, "Borivali")
add_student("Devansh", "Mistry", 46, "Kandivali")
display_students()