-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
51 lines (46 loc) · 1.44 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
43
44
45
46
47
48
49
50
51
import sqlite3 as sq
class DataManage(object):
def __init__(self, db):
global con
self.dbase = db
try:
con = sq.connect(db)
with con:
cur = con.cursor()
cur.execute(
"CREATE TABLE IF NOT EXISTS task(Id INTEGER PRIMARY KEY AUTOINCREMENT, todo TEXT, time TEXT)")
except Exception:
print('Unable to connect to db')
def insert_tasks(self, task):
try:
con = sq.connect(self.dbase)
with con:
cur = con.cursor()
sql = "INSERT INTO task(todo, time) VALUES (?,?)"
cur.execute(sql, task)
return True
except Exception:
print(Exception)
return False
def fetch_tasks(self):
try:
con = sq.connect(self.dbase)
with con:
cur = con.cursor()
sql = "SELECT * FROM task"
cur.execute(sql)
return cur.fetchall()
except Exception:
return False
def delete_tasks(self, id):
try:
con = sq.connect(self.dbase)
with con:
cur = con.cursor()
sql = "DELETE FROM task WHERE id=?"
cur.execute(sql, [id])
con.commit()
cur.close()
return True
except Exception:
return False