-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
95 lines (95 loc) · 3.13 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import sqlite3
class DB(object):
def __init__(self,dbpath):
self.dbpath=dbpath
self.conn=sqlite3.connect(dbpath)
def getForDate(self,date):
c=self.conn.cursor()
t=(date,)
c.execute('select * from tasks WHERE due_date=? ORDER BY pos',t)
r=c.fetchall()
c.close()
return r
def getForId(self,itemid):
c=self.conn.cursor()
t=(itemid,)
c.execute('select * from tasks WHERE id=? ORDER BY pos',t)
r=c.fetchall()
c.close()
return r
def getForWeek(self,week,withoutdates=False):
c=self.conn.cursor()
t=(week,)
if withoutdates:
c.execute('select * from tasks WHERE due_date="thisweek" and due_week=? ORDER BY pos',t)
else:
c.execute('select * from tasks WHERE due_week=? ORDER BY pos',t)
r=c.fetchall()
c.close()
return r
def moveForDate(self,itemid,date,due_week=None):
c=self.conn.cursor()
t=(str(date),due_week,itemid)
c.execute('Update Tasks Set due_date=?, due_week=? Where id=?',t)
c.close()
self.conn.commit()
def setToDone(self,itemid,done):
c=self.conn.cursor()
t=(done,itemid)
c.execute('Update Tasks Set done=? Where id=?',t)
c.close()
self.conn.commit()
def setPos(self,itemids,pos):
c=self.conn.cursor()
for i in pos:
t=(i,itemids[i])
c.execute('Update Tasks Set pos=? Where id=?',t)
c.close()
self.conn.commit()
def editTask(self,itemid,name):
c=self.conn.cursor()
t=(unicode(name),itemid)
c.execute('Update Tasks Set name=? Where id=?',t)
c.close()
self.conn.commit()
def createTask(self,name,ddate=None,due_week=None):
c=self.conn.cursor()
if ddate=="thisweek":
pos=len(self.getForWeek(due_week,True))
else:
pos=len(self.getForDate(ddate))
t=(str(name),ddate,pos,due_week)
c.execute('Insert into Tasks (name,due_date,pos,due_week) Values (?,?,?,?)',t)
newid=c.lastrowid
c.close()
self.conn.commit()
return newid
def setAttr(self,itemid,attrname,attrvalue):
c=self.conn.cursor()
t=(attrname,attrvalue,itemid)
c.execute("Update Tasks Set ?=? Where id=?",t)
c.close()
self.conn.commit()
def checkIfNew(self,name):
c=self.conn.cursor()
t=(str(name),)
c.execute('select * from tasks WHERE name=? COLLATE NOCASE',t)
r=c.fetchall()
c.close()
if len(r)==0:
return False
else:
return r[0]
def getOutdated(self,currentdate,currentweek):
c=self.conn.cursor()
t=(False,currentdate,currentweek)
c.execute('select * from tasks WHERE (done=? or done is NULL) and (due_date<? or (due_date="thisweek" and due_week<?)) ',t)
r=c.fetchall()
c.close()
return r
def deleteTask(self,itemid,):
c=self.conn.cursor()
t=(itemid,)
c.execute("Delete from Tasks Where id=?",t)
c.close()
self.conn.commit()