Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0

Fixed some errors in the implementation of the commit command.

This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-10-08 17:09:31 +00:00
parent 46a606c2bf
commit 2000445902
1 changed files with 13 additions and 9 deletions

View File

@ -50,7 +50,7 @@ q_books_for_category = \
q_new_person = \ q_new_person = \
'INSERT INTO person (id, lastname, firstname) ' \ 'INSERT INTO person (id, lastname, firstname) ' \
'VALUES (%(id)s, %(lastname)s, %(firstname)s' 'VALUES (%(id)s, %(lastname)s, %(firstname)s)'
q_edit_person = \ q_edit_person = \
'UPDATE person ' \ 'UPDATE person ' \
'SET lastname=%(lastname)s, firstname=%(firstname)s ' \ 'SET lastname=%(lastname)s, firstname=%(firstname)s ' \
@ -67,7 +67,7 @@ q_edit_book = \
' subtitle=%(subtitle)s, category=%(category)s, ' \ ' subtitle=%(subtitle)s, category=%(category)s, ' \
' publisher=%(publisher)s, published_year=%(published_year)s, ' \ ' publisher=%(publisher)s, published_year=%(published_year)s, ' \
' edition=%(edition)s, pages=%(pages)s, series=%(series)s, ' \ ' edition=%(edition)s, pages=%(pages)s, series=%(series)s, ' \
' description=%(description)s) ' \ ' description=%(description)s ' \
'WHERE isbn=%(isbn)s' 'WHERE isbn=%(isbn)s'
q_remove_bookpersons = \ q_remove_bookpersons = \
'DELETE FROM bookperson WHERE book=%(isbn)s' 'DELETE FROM bookperson WHERE book=%(isbn)s'
@ -272,6 +272,7 @@ def search_person(connection, search_strings):
pass pass
def do_action(connection, action): def do_action(connection, action):
print 'ACTION %s ' % action
c = connection.cursor() c = connection.cursor()
queries = {'new-person': q_new_person, queries = {'new-person': q_new_person,
'edit-person': q_edit_person, 'edit-person': q_edit_person,
@ -282,8 +283,11 @@ def do_action(connection, action):
action_type = action['action'] action_type = action['action']
c.execute(queries[action_type], action) c.execute(queries[action_type], action)
if action_type in ['new-book', 'edit-book']: if action_type in ['new-book', 'edit-book']:
c.execute(q_remove_bookpersons, action['isbn']) print 'FIXING PERSONS: REMOVING'
for (relation, personlist) in action['persons']: 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: for person in personlist:
c.execute(q_add_bookperson, c.execute(q_add_bookperson,
{'isbn': action['isbn'], {'isbn': action['isbn'],