-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb1.py
53 lines (46 loc) · 1.66 KB
/
db1.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
43
44
45
46
47
48
49
50
51
52
53
import sqlite3
class Database:
#constructor
def __init__(self,db): #db is object of database
#connection variable
self.con=sqlite3.connect(db)
#cursor object-for excecuting every query
self.cur=self.con.cursor()
sql="""
CREATE TABLE IF NOT EXISTS emp(
id Integer Primary key,
name text,
age text,
doj text,
email text,
gender text,
contact text,
address text
)
"""
self.cur.execute(sql)
self.con.commit()
#Insert Function
def insert(self,name,age,doj,email,gender,contact,address):
self.cur.execute("insert into emp values(null,?,?,?,?,?,?,?)",(name,age,doj,email,gender,contact,address))
self.con.commit()
#Fetch All data from DB
def fetch(self):
self.cur.execute("select*from emp")
rows=self.cur.fetchall()
#print(rows)
return rows
#delete a record
def remove(self,id):
self.cur.execute("delete from emp where id=?",(id,))
self.con.commit()
#update a record
def update(self,id,name,age,doj,email,gender,contact,address):
self.cur.execute("update emp set name=?,age=?,doj=?,email=?,gender=?,contact=?,address=? where id=?",
(name,age,doj,email,gender,contact,address,id))
self.con.commit()
#obj1=Database("Emp.db")
#obj1.insert("Sasi","28","12-10-2021","[email protected]","male","7488181331","Sasi Villa")
#obj1.fetch()
# obj1.remove("2")
#obj1.update("3","Manu","25","12-10-2021","[email protected]","male","7488181221","Man8 Villa")