From 76500579928290348653533b4a33cb5a48482769 Mon Sep 17 00:00:00 2001 From: oysteini Date: Sat, 8 Oct 2011 13:50:58 +0000 Subject: [PATCH] Implementasjon av 'list person'. --- cli/worblehat.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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