-
Notifications
You must be signed in to change notification settings - Fork 0
/
mydb.py
executable file
·28 lines (22 loc) · 962 Bytes
/
mydb.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
import sqlite3
class Database:
def __init__(self,db):
self.conn = sqlite3.connect(db)
self.cur = self.conn.cursor()
self.cur.execute("CREATE TABLE IF NOT EXISTS birthRecords(id INTEGER PRIMARY KEY,name varchar(50) NOT NULL, birthday text NOT NULL)")
self.conn.commit()
def fetch(self):
self.cur.execute("SELECT id,name,birthday FROM birthRecords")
rows = self.cur.fetchall()
return rows
def insert(self,name, birthday):
self.cur.execute("INSERT INTO birthRecords VALUES(NULL, ?, ?)", (name, birthday))
self.conn.commit()
def remove(self, id):
self.cur.execute("DELETE FROM birthRecords WHERE id = ?",(id,))
self.conn.commit()
def update(self,id, name, birthday):
self.cur.execute("UPDATE birthRecords SET name = ?, birthday = ? WHERE id = ?" , (name,birthday,id))
self.conn.commit()
def __del__(self):
self.conn.close()