Package orm2 :: Module sql :: Class sql
[hide private]
[frames] | no frames]

Class sql

source code

This class is used to do something that in Haskell is called Cyrrying. This is what leads to the somewhat unusual constructs in this source file, that look like:
 sql(ds)(some_element)

The sql class is instantiated with ds as the constructor's argument. The instance implements the __call__ interface, which enables me to use it like a function. This 'function' is then applied to the some_element parameter. This is especially usefull when programming in a functional style as I did here.

It takes a while to get used to this type of thinking, but it's certainly worthwhile. Some consider this kind of programming beautifull in artistic meaning of the word ;-)

Instance Methods [hide private]
  __init__(self, ds)
  __call__(self, *args)
The arguments must either provide an __sql__() function or be convertable to strings.

Method Details [hide private]

__init__(self, ds)
(Constructor)

source code 
None

__call__(self, *args)
(Call operator)

source code 
The arguments must either provide an __sql__() function or be convertable to strings. The __sql__() function must return either a string containing SQL or a pair as ( SQL, params, ) in which params is a tuple which will be passed to cursor.execute() as second arguments. These are Python instances used by the cursor to replace ?s. This lets the lower level DBAPI module handle the quoting.