On Wednesday, November 30, 2011 5:41:34 PM UTC-5, Chandra wrote: > > I'm going through the official book, currently at the DAL chapter. I'm > having confusions over query and set objects. > > for e.g. > 1. To fetch rows one uses , rows = db(db.mytable.myfield!=None).select() > it returns a collection of rows, that is fine. But, what is a 'set' > then? Isn't 'rows' itself a set of records? >
A Set defines a set of records but doesn't actually select them from the db -- so it's like a conceptual representation of the records, but not the records themselves. When you apply the select() method to the Set, you actually pull the records from the database and transform them to a Python object (a Rows object). The distinction is useful because Sets have other methods besides select(), such as update(), count(), and delete(). > > 2. A query object represents a sql 'where' clause like, myquery = > (db.mytable.myfield != None) | (db.mytable.myfield > 'A') > Can't the same thing be done like, rows = > db((db.mytable.myfield!=None) | (db.mytable.myfield >'A')) > what is the need of having a query object? > What is your proposed alternative? Anthony

