From 200044590266d14e23d4aaf049b0dbe7068044d0 Mon Sep 17 00:00:00 2001 From: oysteini Date: Sat, 8 Oct 2011 17:09:31 +0000 Subject: [PATCH] Fixed some errors in the implementation of the commit command. --- cli/worblehat.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/cli/worblehat.py b/cli/worblehat.py index 978df01..2e87805 100755 --- a/cli/worblehat.py +++ b/cli/worblehat.py @@ -50,7 +50,7 @@ q_books_for_category = \ q_new_person = \ 'INSERT INTO person (id, lastname, firstname) ' \ - 'VALUES (%(id)s, %(lastname)s, %(firstname)s' + 'VALUES (%(id)s, %(lastname)s, %(firstname)s)' q_edit_person = \ 'UPDATE person ' \ 'SET lastname=%(lastname)s, firstname=%(firstname)s ' \ @@ -67,7 +67,7 @@ q_edit_book = \ ' subtitle=%(subtitle)s, category=%(category)s, ' \ ' publisher=%(publisher)s, published_year=%(published_year)s, ' \ ' edition=%(edition)s, pages=%(pages)s, series=%(series)s, ' \ - ' description=%(description)s) ' \ + ' description=%(description)s ' \ 'WHERE isbn=%(isbn)s' q_remove_bookpersons = \ 'DELETE FROM bookperson WHERE book=%(isbn)s' @@ -272,6 +272,7 @@ def search_person(connection, search_strings): pass def do_action(connection, action): + print 'ACTION %s ' % action c = connection.cursor() queries = {'new-person': q_new_person, 'edit-person': q_edit_person, @@ -282,13 +283,16 @@ def do_action(connection, action): action_type = action['action'] c.execute(queries[action_type], action) if action_type in ['new-book', 'edit-book']: - c.execute(q_remove_bookpersons, action['isbn']) - for (relation, personlist) in action['persons']: - for person in personlist: - c.execute(q_add_bookperson, - {'isbn': action['isbn'], - 'person_id': person, - 'relation': relation}) + print 'FIXING PERSONS: REMOVING' + c.execute(q_remove_bookpersons, {'isbn': action['isbn']}) + print 'FIXING PERSONS: ADDING' + if action['persons']: + for (relation, personlist) in action['persons'].items(): + for person in personlist: + c.execute(q_add_bookperson, + {'isbn': action['isbn'], + 'person_id': person, + 'relation': relation}) def commit_actions(connection, actions): for action in actions: