NEEDED: SQL Parser callable from python?

Anthony Baxter anthony at interlink.com.au
Mon Aug 26 06:20:14 CEST 2002


Look into the 'introspect' module in the gadfly project, in particular
the 'RemoteView' class. You can subclass this to allow it to be hooked
into the gadfly core. 

This comment is in my old snmp-tables-via-gadfly code - it looks like it's
still current.

    """A remote view must define self.column_names
       to return a (fixed) list of string column names and
       self.listing() to return a possibly varying
       list of row values.  If there is a single column
       the listing() list must return a list of values,
       but for multiple columns it must return a list
       of tuples with one entry for each column.
       
       The remote view implementation may optionally
       redefine __init__ also, please see introspect.py
    """

A simple (untested!) example might be like:

class MySubclassOfRemoteView(RemoteView):
    # static = 0 means reconstruct internal structures for each
    # query.
    static = 0 
    # these must be fixed
    column_names = [ "user", "extension" ]
    # but the rows returned by this can vary.
    def listing(self):
        return [ ('anthony','7015'), 
                 ('rjones','7002'), 
                 ('rupert','7014'),
               ]

Once you've subclassed RemoteView, something like 

conn = gadfly()
conn.startup("dbtest", "dbtest") # assume directory "dbtest" exists 
conn.add_remote_view("name", MySubclassOfRemoteView() )

will add it to the DB.

For more, check out
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/gadfly/gadfly/gadfly/introspection.py?rev=1.3&content-type=text/vnd.viewcvs-markup

I'm pretty sure this still works with the current state-of-the-art gadfly,
but I can't be sure. 

I can't remember where I found this stuff out - I suspect it was from
asking Aaron in an email. It could probably do with being documented and
some examples and the like... 

Anthony




More information about the Python-list mailing list