Implementasjon av 'list person'.
This commit is contained in:
parent
bf3d8f78a6
commit
7650057992
|
@ -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
|
||||||
|
|
Reference in New Issue