From 570ca6350777acc69429300bea4cc8f8eb97267e Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 23 Apr 2009 06:02:37 +0200 Subject: gui extended, database layout 0.2 sortable and reorderable listview in gui db-version 0.2 with description field (BLOB --- storage/sqlite.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'storage') diff --git a/storage/sqlite.py b/storage/sqlite.py index 5b21054..09e55fc 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.1' + dbVersion = '0.2' def __init__(self): self.con = sqliteBackend.connect(self.getConfigDir() + '/data.sqlite') @@ -22,7 +22,7 @@ class sqlite(storageBase): version = self.cur.execute("select value from control where setting='db-version'").fetchone() if (sqlite.dbVersion,) != version: # TODO: update not init - self.init_db() + self.update_db(version) @@ -47,6 +47,17 @@ class sqlite(storageBase): self.cur.execute("insert into control (setting, value) VALUES ('db-version', ?)", (sqlite.dbVersion,)) self.con.commit() + def update_db(self, updateFrom): + print 'updating todo table...' + if updateFrom == '0.1': + self.cur.execute('''alter table todo + add desc BLOB''') + self.con.commit() + updateFrom = '0.2' + + self.cur.execute("update control set value = ? where setting = 'db-version'", (sqlite.dbVersion,)) + self.con.commit() + def __del__(self): self.con.close() @@ -60,11 +71,11 @@ class sqlite(storageBase): def notifyChange(self, sender): if sender.getId() >= 0: - self.cur.execute('update todo set title=?, createdAt=?, priority=? where id=?', - (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(), sender.getId())) + self.cur.execute('update todo set title=?, createdAt=?, priority=?, desc=? where id=?', + (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(), sender.getId(), sender.getDescription())) self.con.commit() else: - self.cur.execute('insert into todo (title, createdAt, priority) VALUES (?, ?, ?)', - (sender.getTitle(), sender.getCreatedAt(), sender.getPriority())) + self.cur.execute('insert into todo (title, createdAt, priority, desc) VALUES (?, ?, ?, ?)', + (sender.getTitle(), sender.getCreatedAt(), sender.getPriority(), sender.getDescription())) self.con.commit() sender.setId(self.cur.execute('select last_insert_rowid()').fetchone()[0]) -- cgit v1.2.3