-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
42 lines (31 loc) · 1.19 KB
/
db.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
42
import sqlite3
class Database():
def __init__(self,db):
self.con=sqlite3.connect(db)
self.cur=self.con.cursor()
sql="""
CREATE TABLE if not exists student(
id Integer Primary key autoincrement ,
name text ,
gpa text ,
email text ,
section text,
level text,
address text )
"""
self.cur.execute(sql)
self.con.commit()
def insert (self,name ,gpa,email,section,level,address):
self.cur.execute("insert into student values (NULL,?,?,?,?,?,?)", (name ,gpa,email,section,level,address))
self.con.commit()
def fetch(self):
self.cur.execute("SELECT * FROM student")
rows=self.cur.fetchall()
return rows
def remove(self,id):
self.cur.execute("delete from student where id=?",(id,))
self.con.commit()
def update(self,id,name,gpa,email,section,level,address):
self.cur.execute("update student set name=?,gpa=?,email=?,section=?,level=?,address=? where id=?",
(name ,gpa,email,section,level,address,id))
self.con.commit()