Chapter 10.3.2. Getting an Entire Table

Getting all the objects in a table is common. Often, you need to display an entire table or export it to some other medium. SQLObject gives you the select() method. Just call it, and the contents of the entire table are at your fingertips:

class Something(SQLObject):
  name = StringCol()


Something.dropTable(ifExists=True)
Something.createTable()


for i in range(1,11):
  Something(name='Something #%d' % i)


sqlhub.processConnection.debug = 1
sqlhub.processConnection.debugOutput = 1


result = Something.select()

select() doesn’t return a list of SQLObject instances that correspond to rows in your table as you might expect. Instead, it returns an instance of a special type called SelectResults. The idea is to allow ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.