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

Implementasjon av 'list person'.

This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-10-08 13:50:58 +00:00
parent bf3d8f78a6
commit 7650057992
1 changed files with 11 additions and 1 deletions

View File

@ -22,6 +22,10 @@ q_list_books = \
'FROM book ' \ 'FROM book ' \
'LEFT JOIN bookperson ON book.isbn=bookperson.book ' \ 'LEFT JOIN bookperson ON book.isbn=bookperson.book ' \
'LEFT JOIN person ON bookperson.person=person.id' '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 = \ q_persons_for_book = \
'SELECT person.id, lastname, firstname, relation ' \ 'SELECT person.id, lastname, firstname, relation ' \
'FROM person ' \ 'FROM person ' \
@ -173,7 +177,13 @@ def list_books(connection):
print s print s
def list_persons(connection): 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): def list_categories(connection):
pass pass