-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
40 lines (30 loc) · 1.32 KB
/
database.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
import sqlite3
connection = sqlite3.connect('data.db') #file name
TABLE_NAME = "student_table"
STUDENT_ID="student_id"
STUDENT_NAME="student_name"
STUDENT_COLLEGE="student_collage"
STUDENT_ADDRESS="student_sddress"
STUDENT_PHONE="student_phone"
connection.execute(" CREATE TABLE IF NOT EXISTS " +TABLE_NAME +
"(" + STUDENT_ID +
" INTEGER PRIMARY KEY AUTOINCREMENT," +
STUDENT_NAME + " TEXT," + STUDENT_COLLEGE + " TEXT," +
STUDENT_ADDRESS + " TEXT," + STUDENT_PHONE + " INTEGER);" )
def insert(name,college,address,phone):
connection.execute("INSERT INTO " + TABLE_NAME + " ( " +
STUDENT_NAME + "," +
STUDENT_COLLEGE + "," + STUDENT_ADDRESS +
"," + STUDENT_PHONE +
") VALUES ( '" + name + "','" + college + "'," +
"'" + address + "','" + phone + "');")
connection.commit()
def show():
cursor = connection.execute("SELECT * FROM " + TABLE_NAME + ";")
for row in cursor:
print("Student id is:", row[0])
print("Student name is:", row[1])
print("Student collage is", row[2])
print("address is",row[3])
print("phone no. is:",row[4])
connection.commit()