summaryrefslogtreecommitdiffstats
path: root/storage/sqlite.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2009-05-10 19:40:47 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2009-05-10 19:40:47 +0200
commit4bc9b503fa6070e491062d35967d20b37e9c94e0 (patch)
tree9d0d647a4a006db8adf18240418f72b80b4bd0bd /storage/sqlite.py
parent91e7bba27adccc2d9815afed104b678366ecb62a (diff)
downloadtodolist-4bc9b503fa6070e491062d35967d20b37e9c94e0.tar.gz
todolist-4bc9b503fa6070e491062d35967d20b37e9c94e0.tar.xz
todolist-4bc9b503fa6070e491062d35967d20b37e9c94e0.zip
add/remove support
change db layout to version 0.4, with removed column only display items, that are not removed created events for add, remove buttons remove, __delitem__, contains in itemList as proxy to itemList.data added default constructor (if nothing is set) for item to create a new
Diffstat (limited to '')
-rw-r--r--storage/sqlite.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/storage/sqlite.py b/storage/sqlite.py
index bfdae42..7a8e1d8 100644
--- a/storage/sqlite.py
+++ b/storage/sqlite.py
@@ -6,7 +6,7 @@ from item import item
from pysqlite2 import dbapi2 as sqliteBackend
class sqlite(storageBase):
- dbVersion = '0.3'
+ dbVersion = '0.4'
def __init__(self):
self.con = sqliteBackend.connect(self.getConfigDir() + '/data.sqlite')
@@ -34,7 +34,9 @@ class sqlite(storageBase):
title TEXT(255),
createdAt INTEGER,
priority INTEGER,
- desc BLOB
+ desc BLOB,
+ completed INTEGER(1) DEFAULT (0),
+ removed INTEGER(1) DEFAULT (0)
)''')
self.cur.execute('drop table if exists control')
@@ -61,6 +63,12 @@ class sqlite(storageBase):
self.con.commit()
updateFrom = ('0.3',)
+ if updateFrom == ('0.3',):
+ self.cur.execute('''alter table todo
+ add removed INTEGER(1) DEFAULT (0)''')
+ self.con.commit()
+ updateFrom = ('0.4',)
+
self.cur.execute("update control set value = ? where setting = 'db-version'", updateFrom)
self.con.commit()
@@ -69,7 +77,7 @@ class sqlite(storageBase):
def load(self):
items = itemList(self)
- todos = self.cur.execute('select * from todo').fetchall()
+ todos = self.cur.execute('select * from todo where removed=0').fetchall()
for todo in todos:
items += item(row=list(todo))
@@ -77,11 +85,13 @@ class sqlite(storageBase):
def notifyChange(self, sender):
if sender.getId() >= 0:
- self.cur.execute('update todo set title=?, createdAt=?, priority=?, desc=?, completed=? where id=?',
- (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(), sender.getDescription(), sender.getCompleted(), sender.getId()))
+ self.cur.execute('update todo set title=?, createdAt=?, priority=?, desc=?, completed=?, removed=? where id=?',
+ (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(),
+ sender.getDescription(), sender.getCompleted(), sender.getRemoved(), sender.getId()))
self.con.commit()
else:
- self.cur.execute('insert into todo (title, createdAt, priority, desc, completed) VALUES (?, ?, ?, ?, ?)',
- (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(), sender.getDescription(), sender.getCompleted()))
+ self.cur.execute('insert into todo (title, createdAt, priority, desc, completed, removed) VALUES (?, ?, ?, ?, ?, ?)',
+ (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(),
+ sender.getDescription(), sender.getCompleted(), sender.getRemoved()))
self.con.commit()
sender.setId(self.cur.execute('select last_insert_rowid()').fetchone()[0])