Implementert 'list category'.

This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-10-08 13:58:32 +00:00
parent d4ca8c5679
commit b808517be3

View File

@ -23,9 +23,16 @@ q_list_books = \
'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 ' \
'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_list_categories = \
'SELECT category.id, category.name, ' \
' COUNT(book.isbn) AS num_books ' \
'FROM category ' \
'LEFT JOIN book ON category.id=book.category ' \
'GROUP BY category.id, category.name'
q_persons_for_book = \
'SELECT person.id, lastname, firstname, relation ' \
'FROM person ' \
@ -186,7 +193,11 @@ def list_persons(connection):
person['num_books'])
def list_categories(connection):
pass
c = connection.cursor()
c.execute(q_list_categories)
for i in xrange(c.rowcount):
cat = fetchone_dict(c)
print '%-15s %-30s %d books' % (cat['id'], cat['name'], cat['num_books'])
def list_cmd(connection, what):
funs = { 'book': list_books,