Fixed some errors in the implementation of the commit command.
This commit is contained in:
parent
46a606c2bf
commit
2000445902
|
@ -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:
|
||||
|
|
Reference in New Issue