added function to get books in category to dbLayer
authorJohn Ladan <jladan@uwaterloo.ca>
Sat, 31 Mar 2012 00:09:22 +0000 (20:09 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Sat, 31 Mar 2012 00:09:22 +0000 (20:09 -0400)
dbLayer.py

index 687081b..e0e1040 100644 (file)
@@ -123,6 +123,23 @@ def getBooks():
     c.close()
     return books
 
+def getBooksByCategory(cat):
+    conn = sqlite3.connect(dbFile)
+    c = conn.cursor()
+    query = "SELECT "+",".join(columns)+" FROM "+bookTable+" JOIN "+bookCategoryTable+" USING (id) WHERE cat_id = :id;"
+    c.execute(query,cat)
+    books = []
+    for b in c:
+        book = {}
+        i = 0
+        for k in columns:
+            if b[i]!=None:
+                book[k]=b[i]
+            i+=1
+        books.append(book)
+    c.close()
+    return books
+
 def getRemovedBooks():
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()