On Wed, Jan 24, 2007 at 01:39:25PM +0000, Matthew Wilson wrote:
> SomeTable.select(SomeTable.q.Foo > 30)
> 
> Why doesn't the inner parameter, SomeTable.q.Foo > 30, get
> evaluated to some boolean value?

   It doesn't evaluated to boolean. .q is an object that returns special
attributes of type sqlbuilder.SQLExpression. SQLExpression is a special
class that overrides almost all Python magic methods and upon any operation
it, instead of evaluating, it constructs another instance of SQLExpression
that remembers what operation it has to do. A kind of symbolic algebra.
Example: SQLExpression("foo") > 30 produces SQLExpression("foo", ">", 30)
(well, actually it produces SQLExpression(SQLExpression("foo")...))

> How does the select(...) method know
> what to do?

   In short, .select() evaluates the last (top-level) SQLExpression to a
string:
   SQLExpression("foo", ">", 30) => "foo > 30"
and passes the result to the SQL backend.
   The longer but more detailed and correct explanation is that .select()
produces an instance of SelectResults class that upon being iterated over
produces an instance of Iteration class that upon calling its .next()
method (it is iterator!) construct the SQL query string, passes it to the
backend, fetches some results and passes them back to the user.

   For the details of the implementation see sqlobject/main.py for
SQLObject, sqlbuilder.py for SQLExpression, dbconnection.py for
DBConnection class (that constructs the query strings) and Iteration class,
and different subdirectories of sqlobject for concrete implementations of
connection classes - different backends require different query strings.

PS. I would be very grateful if someone fixes my grammar and converts the
text to a documentation patch.

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            [EMAIL PROTECTED]
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to