now adds books to database

This commit is contained in:
John Ladan 2012-03-17 02:39:58 -04:00
parent c390335a87
commit 956a1a9bda
2 changed files with 7 additions and 8 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python
import curses
import sqCatalogue as db
stdscr=0
@ -79,7 +80,7 @@ def redrawForm(w, caption, items, buttonlabel, m):
def lists_to_dict(l1, l2):
book = {}
for k,v in zip(l1,l2):
if v!="":
if v!="" and k.lower()!="publish date":
book[k.lower()]=v
return book
@ -254,7 +255,9 @@ def bookForm(caption, book, buttonlabel):
def addForm():
book = {"title":"A Book of Tests", "pages":"123"}
book = bookForm("Add a book", book, "add")
bookForm("View the book", book, "done")
#bookForm("View the book", book, "done")
if len(book)!=0:
db.addBook(book)
def updateMenu():

View File

@ -14,8 +14,9 @@ CREATE TABLE IF NOT EXISTS books
def colify(s):
return s.replace(" ","_").lower()
# escapes strings and such
def stringify(v):
return '"' + str(v).strip() + '"'
return '"' + str(v).strip().replace('"','""') + '"'
def addBook(book):
conn = sqlite3.connect(dbFile)
@ -28,7 +29,6 @@ def addBook(book):
vals.append(stringify(v))
query = "INSERT INTO "+bookTable+" ("+", ".join(cols)+") VALUES ("+", ".join(vals)+");"
print query
c.execute(query)
conn.commit()
c.close()
@ -41,7 +41,3 @@ def createBooksTable():
c.close()
createBooksTable()
book1 = {"title":"Test Book 1"}
book2 = {"isbn":12345, "title":"Test Book 2"}
addBook(book1)
addBook(book2)