Using database-connection from external methods
Hi! This will hopefulle be my last questions in a while... 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? Can external methods set/send back variables to the calling document/method? Another question while I'm at it - is the DateTime module in 1.10.2 broke in some way? (I get an error if I try to make a new property with the date type set) Help is much appreciated Sture Lygren
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
On Tue, 23 Mar 1999, John Eikenberry wrote:
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
Alternatively your external method can return objects to the calling DTML. for an external method spammethod you could do omething like: class A: pass def spammethod(self,n): a=[] for i in range(n): tmp=A() tmp.no=i a.append(tmp) return a Then in your DTML you can do something like <!--# in "spammethod(20)" sort=no --> <!--# var no --> <!--#/in--> Pavlos
Got it working! Thanks all!! U have been most helpful.
participants (3)
-
John Eikenberry -
Pavlos Christoforou -
raver@box.dust.za.net