From e170717cdd0b05e75579290da7b83795235f7fd9 Mon Sep 17 00:00:00 2001 From: John Ladan Date: Mon, 26 Mar 2012 22:03:13 -0400 Subject: [PATCH] made getCategories more like getBooks (need id as well) --- browser.py | 5 +---- dbLayer.py | 17 +++++------------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/browser.py b/browser.py index 6076052..ae14b25 100644 --- a/browser.py +++ b/browser.py @@ -183,10 +183,7 @@ class categoryBrowser(browserWindow): def refreshCategories(self): - self.entries = [] - cats = db.getCategories() - for c in cats: - self.entries.append({'category':c}) + self.entries = db.getCategories() self.sortByColumn('category') self.selected = map(lambda x:False, self.entries) diff --git a/dbLayer.py b/dbLayer.py index 4be0f29..db1ca8e 100644 --- a/dbLayer.py +++ b/dbLayer.py @@ -182,17 +182,10 @@ def deleteBook(bookid): ######################################### # Category related functions ######################################## -def categorizeBook(bookid, category): +def categorizeBook(bookid, cat_id): conn = sqlite3.connect(dbFile) c = conn.cursor() - if isinstance(category,str): - query = "INSERT OR IGNORE INTO "+categoryTable+" (category) VALUES ("+stringify(cat)+");" - conn.commit() - c.execute(query) - query = "SELECT cat_id FROM "+categoryTable+" WHERE category = "+stringify(category)+";" - c.execute(query) - category = c.fetchone() - query = "INSERT OR IGNORE INTO "+bookCategoryTable+" (id,cat_id) VALUES ("+str(bookid)+", "+str(category)+");" + query = "INSERT OR IGNORE INTO "+bookCategoryTable+" (id,cat_id) VALUES ("+str(bookid)+", "+str(cat_id)+");" conn.commit() c.close() @@ -200,11 +193,11 @@ def categorizeBook(bookid, category): def getCategories(): conn = sqlite3.connect(dbFile) c = conn.cursor() - query = "SELECT category FROM "+categoryTable+";" + query = "SELECT cat_id, category FROM "+categoryTable+";" c.execute(query) cats = [] - for category in c: - cats.append(category[0]) + for cat_id,cat in c: + cats.append({'id':cat_id, 'category':cat}) c.close() return cats