[Zope] type(sql_search())?

Tino Wildenhain tino@wildenhain.de
Mon, 09 Dec 2002 08:01:51 +0100


Hi Hancock,

--On Sonntag, 8. Dezember 2002 21:34 -0800 Terry Hancock 
<hancock@anansispaceworks.com> wrote:

> Can anybody tell me what this mysterious "results object" thing actually
> is?
>
> I'm working from within a Zope product, and defining an SQL() method
> (same as "ZSQLMethod" created within the ZMI). I then call the method
> and get a "list of results". Okay, that's a list, but what are its
> elements?
>
> Aren't they "class instances"?  Why don't they have a __dict__?  What *is*
> this beast, and why isn't it something simple?
>
> I was actually trying to forgo the ridiculously cumbersome path of
> defining a "pluggable brain" with module and class name and passing it to
> the "advanced management" interface of my ZSQLMethod -- i.e. pretending
> I'm doing  everything through the web.  It seems like that really ought
> not to be  necessary in product code. You ought to be able to just slap
> the wrapper on  right in the code, without setting up all that
> boilerplate, e.g.:
>
from Shared.DC.ZRDB.Results.py:

     67         class r(Record, Implicit, brains, zbrains):
     68             'Result record class'
     69
     70         r.__record_schema__=schema
     71         for k in Record.__dict__.keys():
     72             if k[:2]=='__':
     73                 setattr(r,k,getattr(Record,k))
     74
     75         # Add SQL Aliases
     76         d=r.__dict__
     77         for k, v in aliases:
     78             if not hasattr(r,k): d[k]=v
     79
     80         if hasattr(brains, '__init__'):
     81             binit=brains.__init__
     82             if hasattr(binit,'im_func'): binit=binit.im_func
     83             def __init__(self, data, parent, binit=binit):
     84                 Record.__init__(self,data)
     85                 if parent is not None: self=self.__of__(parent)
     86                 binit(self)
     87
     88             r.__dict__['__init__']=__init__
     89
     90         self._class=r

This result set class is just an inner class definition in a list
alike class for the results.
Adding a column could be a little bit harder since the column name
is stored elsewhere. You should look in the definition of Record
and brains to find an interface for this.

Regards
Tino