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

View File

@ -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