-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdbConnect.py
More file actions
38 lines (31 loc) · 1.27 KB
/
Copy pathdbConnect.py
File metadata and controls
38 lines (31 loc) · 1.27 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
36
37
38
import sqlite3
class DBConnect:
def __init__(self):
self._db = sqlite3.connect("Reservation.db")
self._db.row_factory = sqlite3.Row
self._db.execute("create table if not exists Reservation(ID integer primary key autoincrement,"
"FullName text, Gender text, Comment text)")
self._db.commit()
def add(self, name, gender, comment):
self._db.row_factory = sqlite3.Row
# add records
self._db.execute("insert into Reservation(FullName, Gender, Comment) values(?,?,?)",
(name, gender, comment))
self._db.commit()
return "Record is added"
def listInfo(self):
cursor = self._db.execute("select * from Reservation")
return cursor
def deleteRecord(self, ID):
self._db.row_factory = sqlite3.Row
# delete a record
self._db.execute("delete from Reservation where ID = {}".format(ID))
self._db.commit()
return "Record is deleted"
def updateRecord(self, ID, comment):
self._db.row_factory = sqlite3.Row
# update a record
self._db.execute("update Reservation set Comment = ? where ID = ?",
(comment, ID))
self._db.commit()
return "Record is updated"