[Zope] Using database-connection from external methods

John Eikenberry jae@kavi.com
Tue, 23 Mar 1999 11:43:42 -0800 (PST)


On Tue, 23 Mar 1999 raver@box.dust.za.net wrote:

> Is there some way I can reach/use ZMySQL connection method from within an
> external method? Rephrase - I have a connection established within Zope - I
> want to call an external method that handles some sql-queries - is this
> possible, or should I still have the external method handle it's own
> connection?

Just have your external method call ZSQLMethods. For instance, I have an
external method which allows the user to upload a file to the database.
The external method reads the file, parses it, and calls a ZSQLMethod to
update the database.

To do this, assuming your ZSQLMethod is in the acquisition heirarchy,
simply call it like you would any other method. If you have a ZSQLMethod
called 'insert_client', which takes the arguments 'name, company, email',
just call it...

self.insert_client(name=client_name,company=company_name,email=client_email)

 
> Can external methods set/send back variables to the calling document/method?

External methods can modify the current REQUEST object that the DTML uses
from name resolution. If you are calling the external method from within
the DTML, just use 'self.REQUEST' to access the current REQUEST object.
Just create/set items on it like it was a dictionary... 

sekf.REQUEST['new_key'] = new_value

---

John Eikenberry
[jae@kavi.com - http://taos.kavi.com/~jae/] 
______________________________________________________________
"A society that will trade a little liberty for a little order
 will deserve neither and lose both."
                                         --B. Franklin