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 = \
|
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,13 +283,16 @@ 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']})
|
||||||
for person in personlist:
|
print 'FIXING PERSONS: ADDING'
|
||||||
c.execute(q_add_bookperson,
|
if action['persons']:
|
||||||
{'isbn': action['isbn'],
|
for (relation, personlist) in action['persons'].items():
|
||||||
'person_id': person,
|
for person in personlist:
|
||||||
'relation': relation})
|
c.execute(q_add_bookperson,
|
||||||
|
{'isbn': action['isbn'],
|
||||||
|
'person_id': person,
|
||||||
|
'relation': relation})
|
||||||
|
|
||||||
def commit_actions(connection, actions):
|
def commit_actions(connection, actions):
|
||||||
for action in actions:
|
for action in actions:
|
||||||
|
|
Reference in New Issue