diff --git a/cli/worblehat.py b/cli/worblehat.py index 9a14b03..9aab9f3 100644 --- a/cli/worblehat.py +++ b/cli/worblehat.py @@ -22,6 +22,10 @@ q_list_books = \ 'FROM book ' \ 'LEFT JOIN bookperson ON book.isbn=bookperson.book ' \ 'LEFT JOIN person ON bookperson.person=person.id' +q_list_persons = \ + 'SELECT person.id, person.firstname, person.lastname, COUNT(bookperson.id) AS num_books ' \ + 'FROM person LEFT JOIN bookperson ON person.id=bookperson.person ' \ + 'GROUP BY person.id, person.firstname, person.lastname' q_persons_for_book = \ 'SELECT person.id, lastname, firstname, relation ' \ 'FROM person ' \ @@ -173,7 +177,13 @@ def list_books(connection): print s def list_persons(connection): - pass + c = connection.cursor() + c.execute(q_list_persons) + for i in xrange(c.rowcount): + person = fetchone_dict(c) + print '%-5s %-30s %d books' % (person['id'], + person['firstname']+' '+person['lastname'], + person['num_books']) def list_categories(connection): pass